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)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來闸昨,“玉大人蚯斯,你說我怎么就攤上這事《希” “怎么了拍嵌?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長循诉。 經(jīng)常有香客問我横辆,道長,這世上最難降的妖魔是什么茄猫? 我笑而不...
- 正文 為了忘掉前任狈蚤,我火速辦了婚禮,結(jié)果婚禮上划纽,老公的妹妹穿的比我還像新娘脆侮。我一直安慰自己,他們只是感情好勇劣,可當(dāng)我...
- 文/花漫 我一把揭開白布靖避。 她就那樣靜靜地躺著潭枣,像睡著了一般。 火紅的嫁衣襯著肌膚如雪幻捏。 梳的紋絲不亂的頭發(fā)上盆犁,一...
- 文/蒼蘭香墨 我猛地睜開眼讽坏,長吁一口氣:“原來是場噩夢啊……” “哼锭魔!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起路呜,我...
- 正文 年R本政府宣布,位于F島的核電站衷笋,受9級特大地震影響芳杏,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜辟宗,卻給世界環(huán)境...
- 文/蒙蒙 一爵赵、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧泊脐,春花似錦空幻、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽则剃。三九已至,卻和暖如春如捅,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背调煎。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 使用YogaKit來做一個九宮格,看看用它是實現(xiàn)有多簡單赤拒。代碼: 效果: 代碼中的計算量是不是非常少秫筏,都是一些布局...
- 我住在一間可以看見風(fēng)景的房間,在這里挎挖,每天吃著看得見風(fēng)景的早餐这敬,開始我們?nèi)松胁豢稍僦貋淼囊惶臁?法棍+黑咖啡 1...
- 作者:史遇春 本文出自清人何剛德的筆記《春明夢錄》卷上。 何剛德曾任清廷的吏部主事蕉朵。 這一段玻璃窗事件崔涂,雖是小事,...