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)