yogakit

作者: alex_zn | 来源:发表于2018-07-19 14:37 被阅读0次


    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

      本文链接:https://www.haomeiwen.com/subject/hldtmftx.html