Vinod Jadhav
Vinod Jadhav

Reputation: 1065

set dynamic equal height of two uiview depends on their subview using autolayout?

I have one superview in that view there are two subview. I have set equal height of that two view. Those subview height changing respect to label height in it.

This is first screen that i have implemented. It works when label 2 height is greater then label 1 height changes with respect to label 2 height.

enter image description here

This is first screen. It work properly but another situation it is not working when label 1 height is greater than label 2 height then it's not working expected. output like following screen enter image description here As expected label 2 need to adjust with respect label 1 but then also label 1 is adjusted with respect to label 2.

so how to apply constraint for set equal height for two view depends on their subview height.

Upvotes: 0

Views: 992

Answers (2)

ArturOlszak
ArturOlszak

Reputation: 2673

What you are missing is most probably equal height constraint.

Select two container views of the labels and then go to Xcode/Editor/Pin/ and select Height equally.

I've just checked it and its working for me.

Upvotes: 0

Bhanu
Bhanu

Reputation: 1249

You can make your label heigh dynamically

Call a method for UILabel height

-(CGSize) getContentSize_Label:(UILabel*) myLabelView{
    return [myLabelView sizeThatFits:CGSizeMake(myLabelView.frame.size.width, FLT_MAX)];
}

and set label heigh like

   myLabelView.frame = CGRectMake(myLabelView.frame.origin.x, myLabelView.frame.origin.y, myLabelView.frame.size.width, [self getContentSize_Label:myLabelView].height);

and set

  myLabelView.numberOfLines = 0;

Upvotes: 1

Related Questions