Use of masonry under Swift

Source: Internet
Author: User

Masonry is easy to use under OC, but under Swift, the OC method and the property can be used. FUC syntax, swift only properties can be used in the syntax of. Func (). So if you write directly under Swift, it can only be written

        in = make?            . Left.equalto () (self)            = make? . Bottom.equalto () (self)        }
= $0?. Top.left.equalTo () (Self.containerview)?. With (). Offset () (0= Nsvalue (cgsize:cgsize (width:+, Height:$0 ? . Size.equalto () (size)}

 

This kind of writing is very troublesome and unnatural. If the direct use of snapkit and need to introduce a new library, so the landlord has made some changes to masonry. After the change of the wording:

        downtriangle.mas_makeconstraints {             $0. Left.sequalto (self)             $  0. Bottom.sequalto (self)        }

For Mas_equalto it can be written as:

        skilltypetext.mas_makeconstraints {             $0. Top.left.sEqualTo (Self.containerview). with (). Soffset (0)/let            size = Nsvalue (Cgsize:cgsize (width:30, height:15))             $ 0. Size.sequalto (size:cgsize (width:+, Height:))        }

There are several major changes to the following areas:

1.mas_makeconstraints and similar ways to add a __nonnull declaration

-(Nsarray *) Mas_makeconstraints: (void (^ _nonnull) (masconstraintmaker* __nonnull make) block;

2.Masconstraint add attribute declaration, originally wanted to write a category to add a declaration, but failed, it seems that can only be written on the original file.

@property (Nonatomic, Strong,ReadOnly) Masconstraint *Left ; @property (nonatomic, Strong,ReadOnly) Masconstraint *top; @property (nonatomic, Strong,ReadOnly) Masconstraint *Right ; @property (nonatomic, Strong,ReadOnly) Masconstraint *Bottom, @property (nonatomic, Strong,ReadOnly) Masconstraint *Leading, @property (Nonatomic, Strong,ReadOnly) Masconstraint *trailing, @property (nonatomic, Strong,ReadOnly) Masconstraint *width; @property (nonatomic, Strong,ReadOnly) Masconstraint *height; @property (nonatomic, Strong,ReadOnly) Masconstraint *CenterX, @property (nonatomic, Strong,ReadOnly) Masconstraint *CenterY, @property (nonatomic, Strong,ReadOnly) Masconstraint *baseline;

3.swift add Sequalto,sinset and other methods

extension masconstraint{@discardableResult func Sequalto (_ Attr:any?) masconstraint!{        returnSelf.equalto () (attr)} @discardableResult func Sequalto (point:cgpoint)masconstraint!{Let value=Nsvalue (cgpoint:point)returnSelf.equalto () (value)} @discardableResult func Sequalto (size:cgsize)masconstraint!{Let value=Nsvalue (cgsize:size)returnSelf.equalto () (value)} @discardableResult func Sequalto (inset:uiedgeinsets)masconstraint!{Let value=Nsvalue (Uiedgeinsets:inset)returnSelf.equalto () (value)} @discardableResult func Soffset (_ Offset:cgfloat)masconstraint!{        returnSelf.offset () (offset)} @discardableResult func Sinset (_ Inset:uiedgeinsets)masconstraint!{        returnself.insets () (inset)}}

  

Masonry use of various methods there are many, the landlord of the project is also very rushed, generally also encountered a write one. The general changes are similar. Like Nsarray+masaddition basic useless, there is no need to add.

Use of masonry under Swift

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.