1

I have been using AutoLayout feature. Everything works properly, however if I resize any controls programmatically, others subviews or controls are not arranging accordingly. How do I update the constraint after resized any controls programmatically.

or

Will AutoLayout works after resized the control in code?

Edit:

Here I am resizing text view, based on string, but it is overlapping with below subviews.

 - (void)textViewDidChange:(UITextView *)textView
    {
    if (textView == pupose_txt_view) {
        CGSize maximumLabelSize = CGSizeMake(self.topic_text_view.frame.size.width,
                                             FLT_MAX);

        UILabel *label = [[UILabel alloc] initWithFrame:pupose_txt_view.frame];
        CGSize expectedLabelSize = [pupose_txt_view.text sizeWithFont:pupose_txt_view.font
                                      constrainedToSize:maximumLabelSize
                                          lineBreakMode:label.lineBreakMode];


        CGRect newFrame = pupose_txt_view.frame;
        newFrame.size.height = expectedLabelSize.height;
        pupose_txt_view.frame = newFrame;
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Newbee
  • 3,231
  • 7
  • 42
  • 74

1 Answers1

1

You cannot use setFrame: to update the position or size of a view if you are using auto layout. Instead you have to update your constraints to set the new size so the layout system can update the positions of all the views.

To do this you create an outlet for the height constraint of your text size and set it's constant property whenever you want to change the height. You also could remove the constraints for your text view and create new ones, but updating the constants is the preferred way as it requires less code and is more efficient at runtime.

Sven
  • 22,475
  • 4
  • 52
  • 71