IOS _ ZLAutoLayout
At present, there are more and more screens of different sizes in iOS development, making screen adaptation a key point of development.
In the previous development, we either use xib or code to write controls. If you need to stretch, set the enumerated values in View autoresizingMask to set the stretch attribute.
These are all absolute la S.
What are the advantages of AutoLayout?
AutoLayout is relative or absolute.
What is relative and what is absolute?
Relatively, you can use a reference point (View) to constrain its reference point.
It means layout only for the parent View. layout cannot be performed based on the sibling View.
There are already a lot of online AutoLayout tutorials.
Now I want to talk about the ZLAutoLayout framework. I will encapsulate it myself. If there are bugs, please give feedback in time ~~
Code + sample code gitHub address: https://github.com/MakeZL/ZLAutoLayout
The underlying layer also encapsulates the AutoLayout API, but it is much simpler and faster to write.
You only need to import the category file to the project.
-----
Common Methods
-----
// Constrain the parent view, such as view. left = view. superview. left + optional inset. -(void) autoPinSuperViewDirection :( ZLAutoLayoutDirection) direction;-(void) autoPinSuperViewDirection :( ZLAutoLayoutDirection) direction withInset :( CGFloat) inset; // view constraints on the view, such as aView. left = bView. left + optional multiplier + inset. -(void) autoPinDirection :( partial) direction toPinDirection :( partial) toDircetion ofView :( UIView *) view;-(void) autoPinDirection :( partial) direction toPinDirection :( partial) toDircetion ofView :( UIView *) view withInset :( CGFloat) inset;-(void) autoPinDirection :( direction) direction toPinDirection :( direction) toDircetion ofView :( UIView *) ofView multiplier :( CGFloat) multiplier withInset :( CGFloat) inset; // set the view size. Values: (CGSize) (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 vertical direction + optional inset-(void) autoSetAlign :( ZLAutoLayoutAlign) align ofView :( UIView *) ofView;-(void) autoSetAlign :( ZLAutoLayoutAlign) align ofView :( UIView *) ofView withInset :( CGFloat) inset; // make the view and superView have the same constraints-(void) autodesktosuperviewautolayouts;
---- Some code examples ----
Relative layout of two views
// Instance two views 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: zlautolayoutdireleft] relative to the parent control; [redView autoPinSuperViewDirection: zlautolayoutdiretop]; // you can set the redView width to 100, the height is 200 [redView autoSetViewSize: CGSizeMake (100,200)]; // set the width and height of the blueView to the same as that of the redView [blueView layout: Too ofView: redView]; [blueView autoSetViewSizeWidthOrHeight: redView]; // set the Top and Left of the blueView to layout the opposite redView. [blueView autoPinDirection: Too toPinDirection: Too ofView: redView withInset: 20: zlautolayoutdireleft left ofView: redView];
Running Effect