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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 使用YogaKit来做一个九宫格,看看用它是实现有多简单。代码: 效果: 代码中的计算量是不是非常少,都是一些布局...