Coder Social home page Coder Social logo

lcccocoa / snapkitextend Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spicyshrimp/snapkitextend

4.0 2.0 0.0 242 KB

SnapKit的扩展,SnapKit类似于Masonry,但是其没有对Arry的设置和对等间距排列的布局等,此扩展是类似Masonry的写法对SnapKit的补充,同时补充九宫格布局方式

License: MIT License

Ruby 4.56% Swift 95.44%

snapkitextend's Introduction

SnapKitExtend

SnapKit的扩展,SnapKit类似于Masonry,但是其没有对Arry的设置和对等间距排列的布局等,此扩展是类似Masonry的写法对SnapKit的补充,同时补充九宫格布局方式

pod 'SnapKitExtend', '~> 1.0.6'

数组布局

let arr = [view1, view2, view3, view4]
        
arr.snp.makeConstraints{
    $0.width.height.equalTo(100)
    $0.center.equalTo(CGPoint(x: CGFloat(arc4random_uniform(300)) + 50,
                              y: CGFloat(arc4random_uniform(300)) + 50))
}

数组布局2

let arr = [view1, view2, view3, view4]
         
arr.snp.makeConstraints{
    $0.width.height.equalTo(100)
}

view1.snp.makeConstraints{ $0.top.equalTo(0) }
view2.snp.makeConstraints{ $0.top.equalTo(100) }
view3.snp.makeConstraints{ $0.top.equalTo(200) }
view4.snp.makeConstraints{ $0.top.equalTo(300) } 

等间距布局

let arr = [view1, view2, view3, view4]

//        axisType:方向
//        fixedSpacing:中间间距
//        leadSpacing:左边距(上边距)
//        tailSpacing:右边距(下边距)
arr.snp.distributeViewsAlong(axisType: .horizontal, fixedSpacing: 10, leadSpacing: 10, tailSpacing: 10)
//        上面的可以约束x+w,还需要另外约束y+h
//        约束y和height()如果方向是纵向,那么则另外需要设置x+w
arr.snp.makeConstraints{
    $0.top.equalTo(100)
    $0.height.equalTo(CGFloat(arc4random_uniform(100) + 50))
}

等大小布局

let arr = [view1, view2, view3, view4]
        
//        axisType:方向
//        fixedItemLength:item对应方向的宽或者高
//        leadSpacing:左边距(上边距)
//        tailSpacing:右边距(下边距)
arr.snp.distributeViewsAlong(axisType: .vertical, fixedItemLength: 100, leadSpacing: 30, tailSpacing: 30)
//        上面的可以约束y+h,还需要另外约束x+w
//        约束y和height()如果方向是纵向,那么则另外需要设置y+h
arr.snp.makeConstraints{
    $0.width.left.equalTo(100)
}

九宫格布局

var arr: Array<ConstraintView> = [];
for _ in 0..<9 {
    let subview = UIView()
    subview.backgroundColor = UIColor.random
    view.addSubview(subview)
    arr.append(subview)
}

//        固定大小,可变中间间距,上下左右间距默认为0,可以设置
arr.snp.distributeSudokuViews(fixedItemWidth: 100, fixedItemHeight: 100, warpCount: 3)

九宫格布局2

var arr: Array<ConstraintView> = [];
for _ in 0..<9 {
    let subview = UIView()
    subview.backgroundColor = UIColor.random
    view.addSubview(subview)
    arr.append(subview)
}

//        固定间距,可变大小,上下左右间距默认为0,可以设置
arr.snp.distributeSudokuViews(fixedLineSpacing: 10, fixedInteritemSpacing: 10, warpCount: 3)

snapkitextend's People

Contributors

spicyshrimp avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.