IOS ui-Auto Layout (autoresizing)

Source: Internet
Author: User

1 //2 //VIEWCONTROLLER.M3 //Ios_0115_buzhi4 //5 //Created by Ma C on 16/1/15.6 //Copyright (c) 2016 blog technology. All rights reserved.7 //8 9 #import "ViewController.h"Ten  One @interfaceViewcontroller () A@property (nonatomic, strong) UIView *MyView; -  -  the @end -  - @implementationViewcontroller -  +- (void) Viewdidload { - [Super Viewdidload]; +      AUIView *blue =[[UIView alloc] init]; atBlue.frame = CGRectMake (0,0, $, $); -Blue.backgroundcolor =[Uicolor Bluecolor]; - [Self.view Addsubview:blue]; -Self.myview =Blue; -      -UIView *red =[[UIView alloc] init]; inRed.backgroundcolor =[Uicolor Redcolor]; -Red.frame = CGRectMake (0, blue.frame.size.height- -, Blue.frame.size.width, -); to [Blue addsubview:red]; +      -UIButton *btn =[UIButton Buttonwithtype:uibuttontypecustom]; the[Btn Setframe:cgrectmake (Self.view.center.x- -, Self.view.center.y + Max, -, -)]; * [btn Setbackgroundcolor:[uicolor purplecolor]; $     Panax Notoginseng [Self.view addsubview:btn]; -      the [btn addtarget:self Action: @selector (change) forcontrolevents:uicontroleventtouchupinside]; +      A     //Set Autoresizing (if AutoLayout is canceled) the     //set the display rule to set the reference only according to the parent control +Red.autoresizingmask = Uiviewautoresizingflexibletopmargin | Uiviewautoresizingflexiblewidth |Uiviewautoresizingflexibleheight; -      $     /* $ -Bit enumeration - uiviewautoresizingnone = 0, - uiviewautoresizingflexibleleftmargin = 1 << 0, fixed from the right side of the parent control the uiviewautoresizingflexiblewidth = 1 << 1, width varies with parent control - uiviewautoresizingflexiblerightmargin = 1 << 2, fixed from the leftWuyi uiviewautoresizingflexibletopmargin = 1 << 3, the distance below is fixed the uiviewautoresizingflexibleheight = 1 << 4, height varies with parent control - uiviewautoresizingflexiblebottommargin = 1 << 5 distance above is fixed Wu       - the drawbacks of autoresizing About demonstrate a blueview to the left and bottom of the storyboard with the parent control pitch 20, height is $ there's a redview on the right. Its right and bottom are also fixed to the parent control - Two view equal width, equal height, - the distance between the Redview and the Blueview is always 20. Demo cannot do this, then introduce auto Layout -       A      */ + } the  -- (void) Change $ { theCGRect frame =Self.myView.frame; theFrame.size.width + = -; theFrame.size.height + = -; theSelf.myView.frame =frame; -      in } the  the- (void) didreceivememorywarning { About [Super didreceivememorywarning]; the     //Dispose of any resources the can be recreated. the } the  + @end

IOS ui-Auto Layout (autoresizing)

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.