Misunderstanding of storyboard and hand code constraint in development

Source: Internet
Author: User
Tags constant

1. There may still be misunderstandings about storyboard in the development of some companies

Say storyboard is XML, poor performance, and not suitable for team development.

A little move will change the state of storyboard, which has caused great distress in the company's team development, so many companies refuse to use storyboard.

In fact, the above bug is xcode4.x before, Xcode5.0, these bugs have been fixed;

If you really accidentally change the position of a control in storyboard, you can use Git to recover.

Also, in the project as long as a compilation will convert the storyboard into a binary file, in the execution of the process is not very slow, so performance is not much worse

Test: We can display boundle content, find storyboard, at this time cannot be opened with Xcode, can display the package content, enter the following command in the terminal

Terminal command: CD MAIN.STORYBOARDC

Ls

Xxd the file that you want to view. NIB can find that it is already a binary data, a package


2. How do we choose in development?

Advantages of using Xib and storyboard:

1. Can quickly finish the construction of the interface, faster than the hand code, you can quickly see the effect, conducive to debugging

2. It's easy for the new couple to sort out the jump relationships between the modules

The advantages of Pure hand code:

1. Easy to unify management, can quickly change the unified style

2. "Code is king", you can do things storyboard do not

For example: Put a button into a Uilabel, storyboard do not, can only be sibling relationship;

But pure hand code is possible, because Uilabel inherits from UIView, and controls that inherit from UIView can accommodate child controls

In the development we can according to the actual needs of the company and personal interests to choose. However, as an iOS developer, both hand code and storyboard should be used skillfully.


3. Constraints

Use of 1.VFL

"|"      Represents Superview.     |-Spacing-[view1 Object Name--(>=20)-[view2 object name] Do not write h/v means landscape, spacing can write fixed value also can write >/<. Visualize the understanding, "|"     is used to determine the top, bottom, left, and right relationships of a view. To determine the relationship from top to bottom, add v:|. Then the VFL string can describe the relationship between the top and bottom view.

    1 Creating the control UIView *blueview = [[UIView alloc] init];
    [Self.view Addsubview:blueview];
    
    Blueview.backgroundcolor = [Uicolor Bluecolor];
    UIView *redview = [[UIView alloc] init];
    [Self.view Addsubview:redview];
    Redview.backgroundcolor = [Uicolor Redcolor];
    2 disable autoresizing redview.translatesautoresizingmaskintoconstraints = NO;
    
    Blueview.translatesautoresizingmaskintoconstraints = NO; 3 Creating Constraints for constraint//blueview nsarray *blueviewhcon = [Nslayoutconstraint constraintswithvisualformat:@ "H:|-pd1-[bView]-p
    
    d2-| "options:0 metrics:@{@" PD1 ": @20,@" PD2 ": @20} views:@{@" bview ": Blueview}]; Nsarray *blueviewvcon = [Nslayoutconstraint constraintswithvisualformat:@ "V:|-20-[bview (]-20-[rView) ==bView]"
    
    Options:nslayoutformatalignalltrailing metrics:nil views:@{@ "bview": blueview,@ "Rview": RedView}]; Nslayoutconstraint *redviewwidth = [Nslayoutconstraint constraintwithitem:redview attribute:NSLayoutAttributeWidth Relatedby:nslayoutrElationequal Toitem:blueview attribute:nslayoutattributewidth multiplier:0.5 constant:0];
    4 adding constraints [Self.view Addconstraints:blueviewhcon];
    [Self.view Addconstraints:blueviewvcon]; [Self.view Addconstraint:redviewwidth];


2. Hand code constraints

Add Close button UIButton *closebtn = [UIButton buttonwithtype:uibuttontypecustom];
    [Closebtn setbackgroundimage:[uiimage imagenamed:@ "Alphaclose"] forstate:uicontrolstatenormal];
    
    [img ADDSUBVIEW:CLOSEBTN]; Add constraint note/* 1. Close autoreszing 2. Add to Parent control 3. Create constraint 4. Add constraint */CLOSEBTN.TRANSLATESAUTORESIZINGM
    Askintoconstraints = NO; Top Nslayoutconstraint *topc = [Nslayoutconstraint constraintwithitem:closebtn attribute:nslayoutattributetop Relat
    Edby:nslayoutrelationequal ToItem:closeBtn.superview attribute:nslayoutattributetop multiplier:1.0 constant:0]; Right Nslayoutconstraint *RIGHTC = [Nslayoutconstraint constraintwithitem:closebtn attribute:nslayoutattributerigh T relatedby:nslayoutrelationequal ToItem:closeBtn.superview attribute:nslayoutattributeright multiplier:1.0
    CONSTANT:0];  width Nslayoutconstraint *withc = [Nslayoutconstraint constraintwithitem:closebtn attribute:nslayoutattributewidth Relatedby:nslayoutrelaTionequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:1.0 constant:20]; Height Nslayoutconstraint *heightc = [Nslayoutconstraint constraintwithitem:closebtn attribute:nslayoutattributehe ight relatedby:nslayoutrelationequal Toitem:nil Attribute:nslayoutattributenotanattribute multiplier:1.0 constant
    
    : 20];
    Add constraint [img ADDCONSTRAINTS:@[TOPC,RIGHTC]]; [Closebtn ADDCONSTRAINTS:@[WITHC,HEIGHTC]];





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.