Stevia icon indicating copy to clipboard operation
Stevia copied to clipboard

Update the Wiki, more complex examples

Open norbdev opened this issue 4 years ago • 5 comments

The title says everything.

norbdev avatar Mar 23 '20 18:03 norbdev

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

s4cha avatar Mar 30 '20 08:03 s4cha

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

GoldenJoe avatar Apr 19 '20 18:04 GoldenJoe

@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

norbdev avatar May 12 '20 21:05 norbdev

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

sdykae avatar Jun 29 '20 01:06 sdykae

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,

s4cha avatar Jun 29 '20 12:06 s4cha