簡體   English   中英

重新加載UIView和UILabel框架

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM