Auto Layout Sub-view
#import <UIKit/ Uikit.h> @interface viewcontroller : uiviewcontroller { //Create parent View object uiview * _superview; //upper left corner label uilabel * _LABEL01; //upper right Corner label uilabel * _LABEL02; //lower right corner label uilabel * _LABEL03; //lower left corner label uilabel * _LABEL04; //Middle uiview * _viewcenter;} @end
#import "ViewController.h" @interface viewcontroller ()@end @implementation viewcontroller - (void) Viewdidload {[SuperViewdidload];additional setup after loading the view, typically from a nib._superview =[[UIViewAlloc]init]; _superview. Frame= CGRectMake ( -, -, the,280); _superview. BackgroundColor=[UicolorBluecolor];//upper left corner_label01 =[[UILabelAlloc]init];//Position relative to Father view_label01. Frame=cgrectmake (0,0, +, +); _label01. Text[Email protected]"1"; _label01. BackgroundColor=[UicolorOrangecolor];//upper right corner_label02=[[UILabelAlloc]init]; _label02. Frame=cgrectmake ( the- +,0, +, +); _label02. Text[Email protected]"2"; _label02. BackgroundColor=[UicolorOrangecolor];//Lower right corner_label03=[[UILabelAlloc]init]; _label03. Frame=cgrectmake ( the- +,280- +, +, +); _label03. Text[Email protected]"3"; _label03. BackgroundColor=[UicolorOrangecolor];//lower left corner_label04=[[UILabelAlloc]init]; _label04. Frame=cgrectmake (0,280- +, +, +); _label04. Text[Email protected]"4"; _label04. BackgroundColor=[UicolorOrangecolor]; [_superview ADDSUBVIEW:_LABEL01]; [_superview addsubview:_label02]; [_superview ADDSUBVIEW:_LABEL03]; [_superview ADDSUBVIEW:_LABEL04];//Middle_viewcenter =[[UIViewAlloc]init]; _viewcenter. Frame=cgrectmake (0,0, _superview. Frame. Size. Width, +); _viewcenter. Center= Cgpointmake ( the/2,280/2); _viewcenter. BackgroundColor=[UicolorGraycolor]; [_superview Addsubview:_viewcenter]; [ Self. ViewAddsubview:_superview];//Auto Layout property settings, this variable adjusts the position and size of the view in the Father View_viewcenter. Autoresizingmask=uiviewautoresizingflexibletopmargin | uiviewautoresizingflexiblebottommargin| uiviewautoresizingflexiblewidth| Uiviewautoresizingflexiblerightmargin | Uiviewautoresizingflexibleleftmargin;//view can change from the left side of the parent view_label02. Autoresizingmask= Uiviewautoresizingflexibleleftmargin; _label03. Autoresizingmask= Uiviewautoresizingflexibletopmargin | Uiviewautoresizingflexibleleftmargin; _label04. Autoresizingmask= Uiviewautoresizingflexibletopmargin;} -(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{Static BOOLIsLarge =NO; [UIViewBeginanimations:NilContextNil]; [UIViewSetanimationduration:1];if(IsLarge) {_superview. Frame=cgrectmake ( -, -, the,280); Islarge=NO; }Else{_superview. Frame=cgrectmake (Ten,Ten, -,480); Islarge=YES; } [UIViewCommitanimations];} - (void) Didreceivememorywarning {[SuperDidreceivememorywarning];//Dispose of any resources, can be recreated.}@end
iOS development from getting started to mastering-auto layout sub-view