Ios_ about the framework of the encapsulated AutoLayout Zlautolayout

Source: Internet
Author: User

At present, in iOS development, more and more different sizes of screens, so that the screen fit into the development point.

In retrospect, we were either using xib or writing the control in code, and we needed to stretch to set the value of the enumeration inside the view's autoresizingmask to set the Extrude property.

These are absolute layouts.

And what is the advantage of AutoLayout?

AutoLayout is a relative layout and can also be absolutely layout.

What is relative and what is absolute?

Relative refers to a reference point (View) that can be used to constrain it.

Absolutely, layout is only for the parent view, not for the sibling view.



There are so many AutoLayout tutorials on the web.

So now I want to talk about the framework of Zlautolayout , I take the time to package, if there is a bug, please feedback ~ ~


Code + Sample Program for GitHub address: https://github.com/MakeZL/ZLAutoLayout

The bottom layer also encapsulates the API for AutoLayout, but it's much simpler and faster to write.

You only need to import the classification files into the project.


-----

A few common methods

-----

Constraints relative to the parent view, such as View.left = View.superview.left + optional inset.-(void) Autopinsuperviewdirection: (zlautolayoutdirection) direction;-(void) Autopinsuperviewdirection: (zlautolayoutdirection) Direction Withinset: (cgfloat) inset;// View is constrained by view, such as Aview.left = Bview.left + Optional multiplier + inset.-(void) Autopindirection: (zlautolayoutdirection) Direction topindirection: (zlautolayoutdirection) todircetion Ofview: (UIView *) view;-(void) Autopindirection: ( zlautolayoutdirection) Direction topindirection: (zlautolayoutdirection) todircetion Ofview: (UIView *) View Withinset :(cgfloat) inset;-(void) Autopindirection: (zlautolayoutdirection) Direction topindirection: (zlautolayoutdirection) Todircetion Ofview: (UIView *) Ofview multiplier: (cgfloat) multiplier Withinset: (cgfloat) inset;//set view size, width or width to height-( void) Autosetviewsize: (cgsize) size;-(void) Autosetviewsizewidthorheight: (zlautolayoutsize) alsize WithInset: ( CGFloat) inset;//View vertical direction relative to Superview-(void) Autosetaligntosuperview: (zlautolayoutalign) align;-(void) AutosetaliGntosuperview: (zlautolayoutalign) Align Withinset: (cgfloat) inset;//view perpendicular to view + optional inset-(void) Autosetalign: ( zlautolayoutalign) Align Ofview: (UIView *) ofview;-(void) Autosetalign: (zlautolayoutalign) Align Ofview: (UIView *) Ofview Withinset: (cgfloat) inset;//allows view to be as constrained as Superview-(void) autoequaltosuperviewautolayouts;

----part of the Code instance----

Two view relative layouts


Example of two view UIView *redview = [UIView Instanceautolayoutview];    Redview.backgroundcolor = [Uicolor Redcolor];        [Self.view Addsubview:redview];    UIView *blueview = [UIView Instanceautolayoutview];    Blueview.backgroundcolor = [Uicolor Bluecolor];        [Self.view Addsubview:blueview];    Left/top [Redview Autopinsuperviewdirection:zlautolayoutdirectionleft] relative to the parent control;    [Redview Autopinsuperviewdirection:zlautolayoutdirectiontop];        The width of the set Redview is 100 and the height is (redview autosetviewsize:cgsizemake (100, 200)];    Set Blueview with the same width as redview [Blueview autosetviewsizewidthorheight:zlautolayoutsizeheight Ofview:redview];    [Blueview autosetviewsizewidthorheight:zlautolayoutsizewidth Ofview:redview]; Set Blueview top and left relative redview to layout [Blueview autopindirection:zlautolayoutdirectiontop topindirection:    Zlautolayoutdirectionbottom Ofview:redview withinset:20]; [Blueview autopindirection:zlautolayoutdirectionleft Topindirection:zlautolayoutdirectionleft OfView:rEdview]; 


Run effect



Code is a personal package, if there is a bug, please contact me in time Oh ~ ~


Ios_ about the framework of the encapsulated AutoLayout Zlautolayout

Related Article

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.