Allows the system to automatically control the position of the control in the Controller view.

Source: Internet
Author: User

IPhone and iPad often encounter horizontal and vertical screen switching or need to be adjusted automatically. If you cannot use storyboard or XIB to generate an interface, set the frame attribute value of the controller view and add the subview, you can use the autoresizingmask attribute of the view inheritance class (uiview). If you switch between the portrait and landscape screens or use methods such as uipopovercontroller, you can set the frame attribute only once, in the future, the frame attributes will be adaptive (if the frame is scaled down too much, the effect will be poor, depending on the situation ).

Principle: After autoresizingmask is set, when the page size changes, the system will Displayed,All related child views Make automatic adjustments. All controls in the attribute are automatically set to the attribute frame based on autoresizingmask. You can implement system callback in the corresponding-(void) setframe :( cgrect) rect, when the setframe method is called, the system automatically loads the default animation method.
The attributes of uiviewautoresizing are defined as follows:

{

Uiviewautoresizingnone = 0,

Uiviewautoresizingflexibleleftmargin = 1 <0,

Uiviewautoresizingflexiblewidth = 1 <1,

Uiviewautoresizingflexiblerightmargin = 1 <2,

Uiviewautoresizingflexibletopmargin = 1 <3,

Uiviewautoresizingflexibleheight = 1 <4,

Uiviewautoresizingflexiblebottommargin = 1 <5

};

Typedef nsuinteger uiviewautoresizing;

 

Uiviewautoresizingflexibleleftmargin view align to the right

Uiviewautoresizingflexiblewidth view adaptive width

Uiviewautoresizingflexiblerightmargin

Uiviewautoresizingflexibletopmargin view align bottom

Uiviewautoresizingflexibleheight view adaptive height

Uiviewautoresizingflexiblebottommargin

 

Note: The actual alignment directions of leftmargin, rightmargin, topmargin, and bottommargin are the opposite.

 

Example: Make the button always display in the upper right corner of viewcontroller:

 

-(Void) Viewdidload {[Super viewdidload]; uibutton* Right =[Uibutton buttonwithtype: uibuttontyperoundedrect]; right. Frame= Cgrectmake (self. View. Frame. Size. Width-300,0,300,300); Right. autoresizingmask= Uiviewautoresizingflexibleleftmargin | uiviewautoresizingflexiblebottommargin | uiviewautoresizingflexiblewidth |Uiviewautoresizingflexibleheight; [Right settitle:@"456"Forstate: uicontrolstatenormal]; [self. View addsubview: Right];}

 

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: info-contact@alibabacloud.com 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.