xcode/iOS: Autoresize to fill a view - explicit frame size is essential?

前端 未结 2 1891
谎友^
谎友^ 2020-12-12 22:22

I would like a UITextView to fill its superView, which is a plain UIView inside a UIViewController instance.

It s

相关标签:
2条回答
  • 2020-12-12 22:56

    And here Swift 3 solution:

    myView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    
    0 讨论(0)
  • 2020-12-12 23:16

    Autoresizing does not mean that the subview will take up the size of its superview. It just means that it will resize relative to the size change of its superview whenever the superview's bounds change. So initially, you have to set the size of the subview to the correct value. The autoresizing mask will then deal with size changes in the future.

    This is all you need:

    textView = [[[UITextView alloc] autorelease] initWithFrame:self.view.bounds];
    [textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|
                                  UIViewAutoresizingFlexibleHeight];
    
    0 讨论(0)
提交回复
热议问题