More Related Content
Similar to About SnapKit - Open source lab - (20)
More from Daisuke Yamashita (18)
About SnapKit - Open source lab -
- 8. autolayoutで書くと
let redView = UIView()
redView.backgroundColor = UIColor.redColor()
self.view.addSubview(redView)
view.translatesAutoresizingMaskIntoConstraints = false
redView.translatesAutoresizingMaskIntoConstraints = false
redView.addConstraint(
NSLayoutConstraint(item: redView, attribute: .Height,
relatedBy: .Equal,toItem: nil, attribute: .Height, multiplier: 1.0,
constant: 50.0)
)
self.view.addConstraints([
NSLayoutConstraint(item: redView, attribute: .Top, relatedBy: .Equal,
toItem: self.view, attribute: .Top, multiplier: 1.0,
constant: 0.0),
NSLayoutConstraint(item: redView, attribute: .Left, relatedBy: .Equal,
toItem: self.view, attribute: .Left, multiplier: 1.0,
constant: 0.0),
NSLayoutConstraint(item: redView, attribute: .Right, relatedBy: .Equal,
toItem: self.view, attribute: .Right, multiplier: 1.0,
constant: 0.0),
])
- 9. SnapKitで書くと
let redView = UIView()
redView.backgroundColor = UIColor.redColor()
self.view.addSubview(redView)
redView.snp_makeConstraints { (make) -> Void in
make.height.equalTo(50)
make.top.equalTo(view).offset(0)
make.left.equalTo(view).offset(0)
make.right.equalTo(view).offset(0)
}