bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

iOS6+AutoLayout使用教程-創新互聯

為了適配iPhone6 Plus,必須學會AutoLayout了,研究了兩天,記得一下心得iOS6+AutoLayout使用教程

Autolayout類似于安卓里的layout,或者說類似于web開發中的html css,簡單來說就是用相對布局來代替絕對成局(這是我的理解)。

網站制作、成都網站制作服務團隊是一支充滿著熱情的團隊,執著、敏銳、追求更好,是創新互聯的標準與要求,同時竭誠為客戶提供服務是我們的理念。成都創新互聯把每個網站當做一個產品來開發,精雕細琢,追求一名工匠心中的細致,我們更用心!

使用Autolayout有兩種方式,1.用xib配置,2.用代碼寫。

無論用xib還是代碼,需要遵循的一個原則是,一個視圖你必須包含以下兩個限制:1.position,設定x,y坐標、上下左右間隙、居中等這些條件都能確定位置,但這幾個是相互沖突的,只能用其一;2.size, 必須設定尺寸,可以設定固定值的寬高,也可以通過設定寬高比例來等比縮放。

1.用xib配置

這種方式比較直觀,打開xib進行配置即可,具體的使用方法網路上有很多介紹,這里就不細說了

2.用代碼寫

用xib配置應該能完成大部分需要,不過還是會有要用代碼寫的時候,下面是我寫的一個例子,包含了option, metric的用法。

這個例子的效果是:xib里放置了兩個水平居中的butt1,butt3,然后用代碼創建了butt2,butt2與butt3水平居中對齊,最后創建了view1,view1只與根視圖進行布局,與不受其他視圖影響

  //butt2

  {

    UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom];

    butt.backgroundColor = [UIColor redColor];

    [butt setTitle:@"2" forState:UIControlStateNormal];

    butt.translatesAutoresizingMaskIntoConstraints = NO;

    butt.frame = CGRectMake(0, 0, 100, 100);  //這個frame其實是不需要的

    [self.view addSubview:butt];

    butt2 = butt;

    //寬:高 = 1:1

    [butt2 addConstraint:[NSLayoutConstraint constraintWithItem:butt2 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:butt2 attribute:NSLayoutAttributeHeight multiplier:1 constant:0]];

    //butt2與butt3水平對齊,豎直間隙20, 寬定為50

    NSDictionary *viewsDict = NSDictionaryOfVariableBindings(butt3,butt2);

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[butt3]-20-[butt2(==50)]" options:NSLayoutFormatAlignAllCenterX metrics:nil views:viewsDict]];

  }

  //A new view,相對于根視圖布局

  {

    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

    view1.translatesAutoresizingMaskIntoConstraints = NO; //注意,代碼創建的view要設置此屬性為NO以防止系統自動轉換autoresizing

    view1.backgroundColor = [UIColor blueColor];

    [self.view addSubview:view1];

    //1.寬高比1:1.5

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:view1 attribute:NSLayoutAttributeWidth multiplier:1.5f constant:0]];

    //2.固定高度150

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:0.f constant:150.f]];

    //3.水平居中 (3和4只能選其一,因為這兩個限制是沖突的)

    //  [self.view addConstraint:[NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];

    //4.右邊對齊,保留10間隙

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:-10]];

    //5.上下間隔,這里要的效果是保持頂部間隙為100,所以底部間隙要是可變的>=100,試試下面6的效果對比一下

CGFloat hMargin = 100.f;

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-hmar-[view1]-(>=hmar)-|" options:0 metrics:@{@"hmar":@(hMargin)} views:NSDictionaryOfVariableBindings(view1)]];

    //6.上下間隔,頂部間隙可變

    //[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=100)-[view1]-(==100)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view1)]];

  }

關于VFL,請參考蘋果官方文檔: Visual Format Language

另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

當前題目:iOS6+AutoLayout使用教程-創新互聯
網站URL:http://vcdvsql.cn/article4/icgoe.html

成都網站建設公司_創新互聯,為您提供品牌網站建設云服務器做網站網站制作品牌網站制作網站建設

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都做網站