[英]Reload UIView and UILabel Frame
我在筆尖文件中有兩個UILabels
和一個UIView
。 這個筆尖是我的collectionView
的頭。 在我的viewForSupplementaryElementOfKind:
方法中,我需要更改這三個對象的框架。 它們根據header.personCollege
標簽的大小進行更改。
[header.personCollege sizeToFit];
CGRect boxFrame = header.boxView.frame;
boxFrame.origin.x = header.personCollege.frame.origin.x + header.personCollege.frame.size.width + 11;
header.boxView.frame = boxFrame;
CGRect yearFrame = header.personYear.frame;
yearFrame.origin.x = boxFrame.origin.x + boxFrame.size.width + 11;
header.personYear.frame = yearFrame;
[header.personYear setNeedsDisplay];
[header.personCollege setNeedsDisplay];
[header.boxView setNeedsDisplay];
問題是 , setNeedsDisplay
不會更改幀。 僅在調用reloadData
之后才更改幀。 我需要立即更換框架。 我也在使用autoLayout。
由於使用的是AutoLayout,因此應更改與視圖關聯的約束的“常量”值,而不是直接更改其框架。
您可以從創建要更改的約束的IBOutlets / IBOutletCollection開始,然后使用這些IBoutlet可以更改其“常量”值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.