Fahad Rehman
Fahad Rehman

Reputation: 1199

Auto Layout how to move the view2 from right to the bottom?

I have two views in the cell at the left UIImageView and at the right UIView Containing some other views as in picture

enter image description here

Now I want if the width of Cell is => 300 then View2 should be at the right of Screen as it is in picture other wise it should be moved to the bottom of View1

Upvotes: 1

Views: 370

Answers (2)

Punit
Punit

Reputation: 1340

Do one thing. Set another constraints for that view

1) leading to main view

2) top to imageview (you can give this constraint by right click from view to drag imageview then vertical spacing.)

Now give outlets for this two constraints programatically.

And also give outlets for constraints which are: 1) leading from view to imageview 2) top of view.

Now as per your requirement,set if condition

e.g.

if(width => 300)

{

topOfViewToImageviewConstraint.isActive = false

leadingOfViewToMainViewConstraint.isActive = false

}

else

{

leadingOfViewToImageViewConstraint.isActive = false

 topOfviewToMainView.isActive = false

 leadingOfViewToMainViewConstraint.constant = 0

 topOfViewToImageviewConstraint.constant = 20

}

Upvotes: 5

Gabe Spound
Gabe Spound

Reputation: 146

This will work. I am not currently in Xcode, so this is just some sample code, but the idea will work. in cellForRowAt check if self.tableView.cellForRowAt(IndexPath.row).frame.width => 300 if it is, make no change, but if it is not find the y coordinate of the bottom of view 1 and make a new rect at (x: 0, y: botOfView1, width, height). Then set the frame of view 2 equal to that.

Upvotes: 0

Related Questions