Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Wiki, more complex examples #138

Open
norbdev opened this issue Mar 23, 2020 · 5 comments
Open

Update the Wiki, more complex examples #138

norbdev opened this issue Mar 23, 2020 · 5 comments

Comments

@norbdev
Copy link

norbdev commented Mar 23, 2020

The title says everything.

@s4cha
Copy link
Member

s4cha commented Mar 30, 2020

@norbdev I'm all for it, could you elaborate with the type of layout you maybe had trouble with?

@GoldenJoe
Copy link

For one, I think you should have an example specifically explaining that layout doesn't create constraints to the parent by default. This has tripped me up many times:

// No vertical constraint to parent. myView will have a height of 0 without additional constraints.
layout(
    |myView|
)

// No vertical constraint to parent. myView will have a height of 200, but the parent will still have a height of 0 without additional constraints.
layout(
    |myView|
)
myView.Height == 200

// myView will match the height of the parent.
layout(
    0,
    |myView|,
    0
)

// The parent will match the height of myView
layout(
    0,
    |myView|,
    0
)
myView.Height == 200

@norbdev
Copy link
Author

norbdev commented May 12, 2020

@norbdev I'm all for it, could you elaborate with the type of layout you maybe had trouble with?

  • safe area
  • stack view
  • scroll view with content view
  • priority

@sdykae
Copy link

sdykae commented Jun 29, 2020

@s4cha how can I control the overlapping behavior, I was thinking something like ZStack behavior but couldn't find examples :(

@s4cha
Copy link
Member

s4cha commented Jun 29, 2020

Hi @sdyalor, Stevia is pure Autolayout so you can always (and should) use the native way.
The simplest way being changing the view's layer's zPosition value like so :

import UIKit
import Stevia

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let v1 = UIView()
        v1.backgroundColor = .red
        let v2 = UIView()
        v2.backgroundColor = .blue
        
        view.subviews {
            v1
            v2
        }
        
        v1.size(100).centerInContainer()
        v2.size(100).centerHorizontally(offset: 50).centerVertically(offset: 50)
        

        // v1.layer.zPosition = 1 // This makes the red (v1) view show on top
    }
}

Another solution would be to use UIView insertSubview(v1, aboveSubview: v2) and relayout afterwards.

Hope this helps,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants