CosmicMind/Material

[Auto Layout] - How to set constraints relative to a view except parent view?

samma89 opened this issue · 3 comments

Hi @ALL,

I am trying to create a huge form with multiple types of input fields. What I am trying to achieve here is to place all the inputs vertically one after another.

Untitled-1

it seems there is a way like below. but didn't work out for me properly.
Please help!

        let tf = TextField()
        tf.placeholder = "Category Name"
        tf.clearButtonMode = .whileEditing
        
        let tf2 = TextField()
        tf2.placeholder = "Category Description"
        tf2.clearButtonMode = .whileEditing
        
        mainView.formContainer.layout(tf)
            .centerX()
            .leftRight(left: 30, right: 30)
            .top(20)
        
        mainView.formContainer.layout(tf2)
            .centerX()
            .leftRight(left: 30, right: 30)
            .top(tf2, 10)

Thank you

Hi,

I think I figured out after small dive into your source.

I should be using LayoutAnchor implementation of the view as view.anchor yeah?

if yes, let's close this.

Thank you guys!

Hey! So, you want to position the top of t2 to the bottom of tf.

Instead of layout(tf2).top(tf2, 10) you should use layout(tf2).below(tf, 10), or layout(tf2).top(tf.anchor.bottom, 10) both are the same

Thank you @OrkhanAlikhanov for helping out with this issue. @samma89 if you have any further issues or need any help, please reopen or create a new issue. Thank you!