yogakit



    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)
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末帖蔓,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌蚌卤,老刑警劉巖甜无,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件臼氨,死亡現(xiàn)場離奇詭異代兵,居然都是意外死亡,警方通過查閱死者的電腦和手機恭理,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來闸昨,“玉大人蚯斯,你說我怎么就攤上這事《希” “怎么了拍嵌?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長循诉。 經(jīng)常有香客問我横辆,道長,這世上最難降的妖魔是什么茄猫? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任狈蚤,我火速辦了婚禮,結(jié)果婚禮上划纽,老公的妹妹穿的比我還像新娘脆侮。我一直安慰自己,他們只是感情好勇劣,可當(dāng)我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布靖避。 她就那樣靜靜地躺著潭枣,像睡著了一般。 火紅的嫁衣襯著肌膚如雪幻捏。 梳的紋絲不亂的頭發(fā)上盆犁,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天,我揣著相機與錄音篡九,去河邊找鬼谐岁。 笑死,一個胖子當(dāng)著我的面吹牛榛臼,可吹牛的內(nèi)容都是我干的伊佃。 我是一名探鬼主播,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼讽坏,長吁一口氣:“原來是場噩夢啊……” “哼锭魔!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起路呜,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤迷捧,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后胀葱,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體漠秋,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年抵屿,在試婚紗的時候發(fā)現(xiàn)自己被綠了庆锦。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡轧葛,死狀恐怖搂抒,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情尿扯,我是刑警寧澤求晶,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站衷笋,受9級特大地震影響芳杏,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜辟宗,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一爵赵、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧泊脐,春花似錦空幻、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽则剃。三九已至,卻和暖如春如捅,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背调煎。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工镜遣, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人士袄。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓悲关,卻偏偏與公主長得像,于是被迫代替她去往敵國和親娄柳。 傳聞我的和親對象是個殘疾皇子寓辱,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容