Reputation:
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]];
Upvotes: 0
Views: 436
Reputation: 93
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.
Upvotes: 1