[英]How can I place a UILabel below an UIImageView such that it is always evenly placed
由於您不使用情節提要板,因此以下代碼將幫助您設置標簽框架:-
UILabel *labelName;//This will be your label instance
CGFloat yAxis = 50;//This will be your image view's y axis + image view's height
[labelName setFrame:CGRectMake(0, yAxis, self.view.frame.size.width, self.view.frame.size.height)];
//Set the color/Font other properties of label as desired
[labelName setTextAlignment:NSTextAlignmentCenter];
設置約束是有效的解決方案。
您可以按照Mr.UB的建議使用情節提要方式,也可以按照代碼方式進行操作。如果您希望按代碼進行操作,建議您使用Masonry來設置約束。
您可以簡單地執行以下操作:
[your-label mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(imgView.mas_top); //with is an optional semantic filler
make.mas_centerX.equalTo(imgView.mas_centerX);
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.