Set UIView's autoresizing mask programmatically?

前端 未结 5 1182
青春惊慌失措
青春惊慌失措 2021-02-01 00:56

I have to set autoresizingMask programmatically for UIView.

I don\'t know how to implement this.

5条回答
  •  南笙
    南笙 (楼主)
    2021-02-01 01:11

    You have to set the view's autoresizingMask property:

    view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    

    The possible values are defined in UIViewAutoresizing:

    enum {
       UIViewAutoresizingNone                 = 0,
       UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
       UIViewAutoresizingFlexibleWidth        = 1 << 1,
       UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
       UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
       UIViewAutoresizingFlexibleHeight       = 1 << 4,
       UIViewAutoresizingFlexibleBottomMargin = 1 << 5
    };
    typedef NSUInteger UIViewAutoresizing;
    

    You can set multiple values with the bitwise OR operator |.

提交回复
热议问题