我有一個UIView不能填滿整個屏幕,我想爲該視圖添加頂部邊框。不過,我不斷收到以下:什麼時候應該在UIViews中設置邊框?
這裏是我使用的代碼:
CGFloat thickness = 4.0f;
CALayer *topBorder = [CALayer layer];
topBorder.frame = CGRectMake(0, 0, self.announcementCard.frame.size.width, thickness);
topBorder.backgroundColor = [UIColor blueColor].CGColor;
我怎麼知道爲什麼邊境熄滅屏幕。這是因爲我把邊界放在UIViews init方法的視圖中。當我這樣做時self.announcementCard.frame.size.width
是1000,因此邊框離開屏幕。 self.announcementCard.frame.size.width
的寬度和高度爲1000.原因是因爲UIView沒有在其init方法中將約束添加到UIView。
因此,我的問題是我應該在什麼時候調用我上面寫的代碼? self.announcementCard.frame.size.width
何時會添加約束並更新其框架?