简体   繁体   中英

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 . 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 ? 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. 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 . In right side corner attribute inspector Line = 0 and line breaks = word wrap

then set constraints leading, trailing, top, bottom for UITextview . if UITextview height is fixed size means set height for UITextview .

must place both the component in UIScrollview .

it will flexible, while label height will increase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM