[英]Constraints without using auto-layout?
I am not using auto-layout, and I want to know if I can specify constraints between a UILabel
and a UITextView
. 我没有使用自动布局,我想知道是否可以在
UILabel
和UITextView
之间指定约束。 I tried what is mentioned here , but I got an error View hierarchy unprepared for constraint
, so I looked up for that and found this , the accepted answer says that the views I am trying to add constraints to must be the subviews, if that is correct how can I add constraints so that the X position
of my UITextView
is set according to the height of UILabel
? 我尝试了这里提到的内容,但是出现了一个错误的
View hierarchy unprepared for constraint
做View hierarchy unprepared for constraint
,因此我查找了该对象并发现了这个问题 ,可接受的答案是,我要添加约束的视图必须是子视图,如果那是更正如何添加约束,以便根据UILabel
的高度设置UITextView
的X position
? I will post a picture so that it will give you all a clear idea: 我将发布一张图片,以便给大家一个清晰的主意:
Now I don't know if the UILabel
is a single line or a couple of lines, and I want my UITextView
to adjust it's X-position accordingly. 现在,我不知道
UILabel
是单行还是几行,我希望UITextView
地调整它的X位置。 This is the code I added, since I just learned about it please let me know if it is correct: 这是我添加的代码,因为我刚刚了解了它,所以请告诉我它是否正确:
NSLayoutConstraint *xConstraint=[NSLayoutConstraint constraintWithItem:self.tvNewsDetails attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.lblNewsTitle attribute:NSLayoutAttributeBottom multiplier:0.45 constant:0];
[self.tvNewsDetails addConstraints:@[xConstraint]];
First you set leading, trailing, top, bottom for UILabel
. 首先,为
UILabel
设置前导,尾随,顶部,底部。 In right side corner attribute inspector Line = 0 and line breaks = word wrap 在右侧角属性检查器中,Line = 0和换行符=自动换行
then set constraints leading, trailing, top, bottom for UITextview
. 然后为
UITextview
设置前,尾,上,下UITextview
。 if UITextview
height is fixed size means set height for UITextview
. 如果
UITextview
高度为固定大小,则意味着设置UITextview
高度。
must place both the component in UIScrollview
. 必须将两个组件都放在
UIScrollview
。
it will flexible, while label height will increase. 它会灵活,而标签高度会增加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.