Ui3_uiview Automatic Layout

Source: Internet
Author: User

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

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.