func flexBox() {
let contentV = UIView()
contentV.backgroundColor = .lightGray
view.addSubview(contentV)
let child1 = UIView()
child1.backgroundColor = UIColor.red
child1.configureLayout { (layout) in
layout.isEnabled = true
layout.width = 80
layout.height = 80
layout.margin = 20
}
let child2 = UIScrollView()
child2.backgroundColor = UIColor.blue
child2.configureLayout { (layout) in
layout.isEnabled = true
layout.width = 280
layout.height = 100
layout.margin = 20
layout.flexDirection = .row
layout.alignItems = .center
let v1 = UIView.init(color: UIColor.black)
let v2 = UIView.init(color: UIColor.green)
let v3 = UIView.init(color: UIColor.brown)
v1.configureLayout(block: { (y1) in
y1.isEnabled = true
y1.width = 100
y1.height = 40
})
v2.configureLayout(block: { (y2) in
y2.isEnabled = true
y2.width = 100
y2.height = 40
})
v3.configureLayout(block: { (y3) in
y3.isEnabled = true
y3.width = 100
y3.height = 40
})
child2.addSubview(v1)
child2.addSubview(v2)
child2.addSubview(v3)
child2.yoga.applyLayout(preservingOrigin: true)
child2.contentSize.width = 300
}
let child3 = UIView()
child3.backgroundColor = UIColor.yellow
child3.configureLayout { (layout) in
layout.isEnabled = true
layout.width = 180
layout.height = 180
layout.margin = 20
}
let child4 = UIView()
child4.backgroundColor = UIColor.cyan
child4.configureLayout { (layout) in
layout.isEnabled = true
layout.width = 100
layout.height = 100
layout.margin = 20
}
contentV.addSubview(child1)
contentV.addSubview(child2)
contentV.addSubview(child3)
contentV.addSubview(child4)
contentV.configureLayout { (make) in
make.isEnabled = true
make.flexDirection = .row
make.alignItems = .center
make.padding = 20
make.flexWrap = .wrap
make.width = YGValue(self.view.bounds.size.width)
}
view.configureLayout { (make) in
make.isEnabled = true
make.alignItems = .spaceBetween
make.width = YGValue(self.view.bounds.size.width)
make.height = YGValue(self.view.bounds.size.height)
let scroller = UIScrollView()
scroller.backgroundColor = UIColor.groupTableViewBackground
scroller.configureLayout(block: { (y) in
y.height = 400
y.isEnabled = true
y.flexDirection = .column
})
self.view.addSubview(scroller)
scroller.addSubview(contentV)
scroller.yoga.applyLayout(preservingOrigin: true)
scroller.contentSize = contentV.bounds.size
}
view.yoga.applyLayout(preservingOrigin: true)
}
yogakit
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 使用YogaKit来做一个九宫格,看看用它是实现有多简单。代码: 效果: 代码中的计算量是不是非常少,都是一些布局...