Autoresizingmask in iOS (reproduced)

Source: Internet
Author: User

The original address is as follows, thank the original author! Recommend the original address to read! I wrote a little bit of my experience on his basis.


There is a Autoresizingmask property in UIView, which corresponds to the value of an enumeration (as follows), which means that the position of the child control and the parent control is automatically adjusted to a height of width.

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

Uiviewautoresizingnone is not automatically adjusted.
Uiviewautoresizingflexible The distance to the right is constant .
Uiviewautoresizingflexible. The
Uiviewautoresizingflexibletopmargin automatically adjusts the distance from the top of the Superview to ensure that the distance from the bottom of the Superview is constant. The
Uiviewautoresizingflexiblebottommargin automatically adjusts the distance from the bottom of the Superview, that is, the distance from the top of the Superview is unchanged.
Uiviewautoresizingflexiblewidth automatically adjusts its own width to ensure that the Superview.
Uiviewautoresizingflexibleheight automatically adjusts its height to ensure that it is Superview.
uiviewautoresizingflexibleleftmargin  | Uiviewautoresizingflexiblerightmargin automatically adjusts the distance to the left of the superview to ensure that the distance to the left and to the right is the same as the distance from the left and right. For example, the original distance is 20, 30, the adjusted distance should be 68,102, that is, 68/20=102/30.

The last one needs attention. There are many changes that are derived from this rule.

In addition, although the number of variables here is similar to the settings in Xib, the Xib setting does not correspond to the variable one by one here. For example, the following code is the corresponding:

Self.testBtn.autoresizingMask = Uiviewautoresizingflexiblewidth;

This is also a problem that bothers me for a long time! Xib Select 3, you only need to set one in the code! So don't assume that the wrong code constraints are written according to the settings in the Xib!

Autoresizingmask in iOS (reproduced)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.