Autolayout 中的 百分比 宽度
http://maogm.com/blog/percentage-width-in-autolayout.html
這招太實用啦
1.先設定該元件與父元件Equal Width的Constraint
2.再將該Constraint的Multiplier設定需要的比例(ex: 0.5,表示50%)
为iPhone6设计自适应布局(一)
http://www.devtalking.com/articles/adaptive-layout-for-iphone6-1/
SnapKit
居中
let view1 = UIView() view.addSubview(view1) view1.snp_makeConstraints{(make)->Void in make.edges.equalTo(view).insets(UIEdgeInsetsMake(20, 20, 20, 20)) }
等宽
let view2 = UIView() let view3 = UIView() view1.addSubview(view2) view1.addSubview(view3) view1.addSubview(view4) view2.snp_makeConstraints{(make)->Void in make.top.equalTo(view1.snp_top).offset(20) make.width.equalTo(view3) make.left.equalTo(view1.snp_left).offset(20) make.right.equalTo(view3.snp_left).offset(-20) make.height.equalTo(200) } view3.snp_makeConstraints{(make)->Void in make.top.equalTo(view1.snp_top).offset(20) make.width.equalTo(view2) make.right.equalTo(view1.snp_right).offset(-20) make.left.equalTo(view2.snp_right).offset(-20) make.height.equalTo(200) }
相对在下
let view4 = UIView() view4.backgroundColor = getColor(0xC795FF) view1.addSubview(view4) view4.snp_makeConstraints{(make)->Void in make.width.equalTo(view1).offset(-40) make.centerX.equalTo(view.snp_centerX) make.top.equalTo(view2.snp_bottom).offset(20) make.bottom.equalTo(view1.snp_bottom).offset(-20) }
留言
張貼留言