ZTLayout

preface

ZTLayout is a simple encapsulation of SnapKit that uses custom operators to reduce the amount of code needed for regular, sequential layout work

The concrete implementation and Demo code are as follows: Github address

For reference only, hope to help, if you have any good way, please let me know, thanks.

The following are examples of the effects shown and explanations:

The operator

*>> : Sets layout parameters

>>> : Adds a View to the view and returns the parent view

/> “xx” : use SnapKit for all descendants of view layout;

The right string can be filled in with any character. This is written because only the relay operator can adjust the priority of the operation

> > | : > > >, and set the layout parameters. EqualToSuperviews = [} {$0. Right]

Note The right side of the view must overlap with the right side of the superView, which is used to set the width of the Superview

EqualToSuperviews = [{$0. Bottom}]

Note The lower part of view must overlap with the lower part of superview, which is used to set the height of superview

> > > / : > > >, and set the layout parameters. EqualToSuperviews = [} {$0. Right,} {$0. Bottom]

Note The right and bottom sides of the view must overlap with the right and bottom sides of the SuperView, which is used to set the width and height of the SuperView

= = = =

Nested operators (up to three levels, using >>> {} closure implementations to continue nesting)

+ + + + >, + + |, /, + + > /

+ + + + + + >, |, + + + / + + + > /

+ + + + + + + + >, |, + + + + / + + + + > /

Code demo

  1. Sample single-layer layout

Code: The original code

Simplification 1: You can omit the creation of the ZTLayout object

Simplification 2: Use operator >>/

Simplification 3: Closure loop creation

Simplification 4: The *>> operator can be passed directly into the ZTLayoutConfig object

  1. Examples of nested layers

Original code:

Simplify: Use operators

  1. Create multiple groups of views quickly

Code: