viewcontroller.m//Ui3_uiview Automatic Layout////Created by zhangxueming on 15/7/1.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void ) Viewdidload {[Super viewdidload]; Additional setup after loading the view, typically from a nib. Auto layout cgfloat size = self.view.frame.size.width-300; UIView *view = [[UIView alloc] Initwithframe:cgrectmake ($, a, size, size)]; View.backgroundcolor = [Uicolor Orangecolor]; Open child View Auto layout view.autoresizessubviews = YES; Uiviewautoresizingnone = 0,//is not automatically adjusted//Uiviewautoresizingflexibleleftmargin = 1 << 0,// Automatically adjusts the distance to the left of the superview to ensure that the distance to the right of the Superview is constant. Uiviewautoresizingflexiblewidth = 1 << 1,//automatically adjusts its width to ensure that the distance to the left and right of the Superview is constant//Uiviewautoresizi Ngflexiblerightmargin = 1 << 2,//automatically adjusts the right distance from the Superview to ensure that the distance from the left side of the Superview is constant. UiviewautoresizingflexiblEtopmargin = 1 << 3,//automatically adjusts the distance from the top of the Superview to ensure that the distance from the bottom of the Superview is constant. Uiviewautoresizingflexibleheight = 1 << 4,//automatically adjusts its height to ensure that the distance from the top and bottom of the Superview is constant. Uiviewautoresizingflexiblebottommargin = 1 << 5//automatically adjusts the distance from the bottom of the Superview, that is, the distance from the top of the Superview does not change. Set Tag Value View.tag = 100; Auto Trim view.clipstobounds = YES; [Self.view Addsubview:view]; UIView *topview = [[UIView alloc] Initwithframe:cgrectmake (5, 5, size-10, size-10)]; Topview.backgroundcolor = [Uicolor Greencolor]; Set the child view to be consistent with the surrounding distance of the parent view Topview.autoresizingmask = uiviewautoresizingflexiblewidth| Uiviewautoresizingflexibleheight; [View Addsubview:topview]; UIButton *btn = [UIButton Buttonwithtype:uibuttontypesystem]; Btn.frame = CGRectMake (self.view.frame.size.width-200, 30); Btn.backgroundcolor = [Uicolor Cyancolor]; [Btn settitle:@ "click" Forstate:uicontrolstatenormal]; [Btn addtarget:self Action: @selector (btnclicked) forcontroleventS:uicontroleventtouchupinside]; [Self.view addsubview:btn];} Modifies the parent view's frame-(void) btnclicked{UIView *view = [Self.view viewwithtag:100]; CGRect frame = CGRectMake (view.frame.origin.x-1,view.frame.origin.y-1,view.frame.size.width+2, VIEW.FRAME.SIZE.HEIGHT+2); View.frame = frame;} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Ui3_uiview Automatic Layout