Giter VIP home page Giter VIP logo

Comments (1)

youngsoft avatar youngsoft commented on May 24, 2024

您好,您的需求是A和C均分S的高度,而且A和S,A和C,以及S和C之间要有10的间隔对吧。上面的代码您写复杂了。

这个需求你可以用线性布局来实现
        let  S = TGLinearLayout(.vert)
        S.backgroundColor = UIColor.lightGray
        S.tg_width.equal(100)
        S.tg_height.equal(400)
        S.tg_top.equal(64)
        S.tg_topPadding = 10  //子视图顶部边距为10
        S.tg_bottomPadding = 10  //子视图顶部边距为10
        S.tg_vspace = 10   //子视图之间的间距为10
        view.addSubview(S)
        let  A = UIView()
        let  C = UIView()
        C.backgroundColor = UIColor.blue
        A.backgroundColor = UIColor.red
        A.tg_width.equal(.fill).and().tg_height.equal(.fill)   //高度和宽度都是填充或者A.tg_size(width:.fill, height:.fill)
        C.tg_width.equal(.fill).and().tg_height.equal(.fill)
        S.addSubview(A)
        S.addSubview(C)
        
或者线性布局更加简单来实现
       let  S = TGLinearLayout(.vert)
        S.backgroundColor = UIColor.lightGray
        S.tg_width.equal(100)
        S.tg_height.equal(400)
        S.tg_top.equal(64)
        S.tg_topPadding = 10  //子视图顶部边距为10
        S.tg_bottomPadding = 10  //子视图顶部边距为10
        S.tg_vspace = 10   //子视图之间的间距为10
        S.tg_gravity = .fill  //里面的子视图宽度和高度都填充。
        view.addSubview(S)
        let  A = UIView()
        let  C = UIView()
        C.backgroundColor = UIColor.blue
        A.backgroundColor = UIColor.red
        S.addSubview(A)
        S.addSubview(C)
这个需求你可以用相对布局来实现(具体例子见相对布局第2个例子)
        let  S = TGRelativeLayout()
        S.backgroundColor = UIColor.lightGray
        S.tg_width.equal(100)
        S.tg_height.equal(400)
        S.tg_top.equal(64)
        S.tg_topPadding = 10  //子视图顶部边距为10
        S.tg_bottomPadding = 10  //子视图顶部边距为10
        view.addSubview(S)
         let A = UIView()
         let C = UIView()
        C.backgroundColor = UIColor.blue
        A.backgroundColor = UIColor.red
        A.tg_width.equal(.fill)
        C.tg_width.equal(.fill)
        
        A.tg_height.equal([C.tg_height.add(-5)], increment:-5)   //这里采用数组的方式来进行高度均分,都减去5来保留10的子视图间隙
        C.tg_top.equal(A.tg_bottom, offset:10)
        
        S.addSubview(A)
        S.addSubview(C)

from tangramkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.