iOS development from getting started to mastering-auto layout sub-view

Source: Internet
Author: User
Tags uikit

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

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.