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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關(guān)閱讀更多精彩內(nèi)容
- 使用YogaKit來做一個九宮格,看看用它是實現(xiàn)有多簡單。代碼: 效果: 代碼中的計算量是不是非常少,都是一些布局...