LoginSignup
3
4

More than 5 years have passed since last update.

PureLayoutで使う制約の種類

Last updated at Posted at 2016-10-20

pureLayoutの勉強(随時更新)

pureLayout
https://github.com/PureLayout/PureLayout

コードベースで簡潔に制約を設定するためのライブラリ(と理解してます)

インストール後は

import PureLayout

class ViewController: UIViewController {
~
}

ですぐ使えます。

view間の制約

autoPinEdge
autoPinEdgeToSuperviewEdge
autoPinEdgesToSuperviewEdges
autoCenterInSuperview
autoAlignAxis(toSuperviewAxis: ALAxis)
autoAlignAxis(ALAxis, toSameAxisOf: UIView)

viewA.autoPinEdge(.Bottom, toEdge: .Top, ofView: viewB)
viewA.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 30)
viewA.autoPinEdgesToSuperviewEdges() // superviewと同じ大きさになる
viewA.autoCenterInSuperview() // viewAをsuperViewのセンターに配置
viewA.autoAlignAxis(toSuperviewAxis: .vertical) // superviewのverticalと一致させる
viewA.autoAlignAxis(.horizontal, toSameAxisOf: viewB) // viewBのhorizontalと一致させる

サイズの制約

autoSetDimension
autoSetDimensionsToSize

//cgfloatで個別にセット
view.autoSetDimension(.Width, toSize: 100)
view.autoSetDimension(.Height, toSize: 100)

// cgsizeでセット
view.autoSetDimensionsToSize(CGSize(width: 100 ,height: 100))

制約のセット、解除

autoInstallConstraints
autoRemoveConstraints

// layoutConstraintsは制約の配列
//    layoutConstraints = NSLayoutConstraint.autoCreateAndInstallConstraints{
//        self.viewA.autoCenterInSuperview()
//    } as NSArray?


self.layoutConstraints?.autoInstallConstraints() // layoutConstraintsを適用
self.layoutConstraints?.autoRemoveConstraints() // layoutConstraintsを解除
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4