import UIKit
import SnapKit
let margin = 10
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 设置UI
setupUI()
}
func setupUI(){
self.view.addSubview(contentView)
contentView.addSubview(headImageView)
contentView.addSubview(nameLable)
contentView.addSubview(zanImageView)
self.view.addSubview(siderView)
contentView.snp_makeConstraints { (make) -> Void in
make.top.equalTo(self.view.snp_top).offset(margin*3)
make.left.right.equalTo(self.view)
make.height.equalTo(50)
}
headImageView.snp_makeConstraints { (make) -> Void in
make.left.equalTo(contentView.snp_left).offset(margin)
make.top.equalTo(contentView.snp_top).offset(margin)
make.size.equalTo(CGSizeMake(30, 30))
}
nameLable.snp_makeConstraints { (make) -> Void in
make.left.equalTo(headImageView.snp_right).offset(margin)
make.top.equalTo(contentView.snp_top).offset(margin)
}
zanImageView.snp_makeConstraints { (make) -> Void in
make.left.equalTo(nameLable.snp_right).offset(margin)
make.top.equalTo(contentView.snp_top).offset(margin)
make.right.lessThanOrEqualTo(contentView.snp_right).offset(-margin)
}
siderView.snp_makeConstraints { (make) -> Void in
make.top.equalTo(contentView.snp_bottom).offset(margin)
make.left.equalTo(self.view.snp_left).offset(margin)
make.right.equalTo(self.view.snp_right).offset(-margin)
make.height.equalTo(10)
}
}
// MARK - response
func updateAdjustSliderValue(sender : UISlider){
if sender.isKindOfClass(UISlider){
let f = sender.value
self.contentView.snp_updateConstraints { (make) -> Void in
make.left.equalTo(self.view).offset(f)
}
}
}
// MARK - getter and setter
// contentView
private lazy var contentView : UIView = {
let view = UIView()
return view
}()
// 头像
private lazy var headImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "get")
return imageView
}()
// 姓名
private lazy var nameLable : UILabel = {
let lable = UILabel()
lable.text = "测试AutoLayout优先级"
lable.setContentCompressionResistancePriority(UILayoutPriorityDefaultLow, forAxis: UILayoutConstraintAxis.Horizontal)
return lable
}()
// 点赞图片
private lazy var zanImageView : UIImageView = {
let zanImageVeiw = UIImageView()
zanImageVeiw.image = UIImage(named: "money")
zanImageVeiw.setContentCompressionResistancePriority(UILayoutPriorityDefaultHigh, forAxis: UILayoutConstraintAxis.Horizontal)
return zanImageVeiw
}()
// sider
private lazy var siderView : UISlider = {
let sideView = UISlider()
sideView.minimumValue = 10.0
sideView.maximumValue = 200
sideView.minimumTrackTintColor = UIColor.lightGrayColor()
sideView.addTarget(self, action: Selector("updateAdjustSliderValue:"), forControlEvents: UIControlEvents.ValueChanged)
return sideView
}()
}
练习setContentCompressionResistancePriority
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 小学语文修改病句的方法 修改病句是小学语文考试中常见的题型,在修改病句之前,我们应该清晰的了解有哪些病句现象,下面...
- 成长记录-连载(三十六) ——我的第一篇五千字长文,说了什么,你一定想不到 并不是不想每天写公众号,而是之前思考怎...
- 一般来说,喜欢站立的人,比喜欢躺着或或坐着的人,身材更好。与躺着的姿势相比,站姿所消耗的能量要多出10%。而单腿站...