I have an UIView
inside which i have a UIButton
. I am using auto layout. Now I want to reduce the height of the UIView
. How should I do it ? On reducing the height of the UIView
, the UIButton
inside the view should also move up at the same time. How can i do this using Auto Layout ?
Asked
Active
Viewed 150 times
-1

MainakChoudhury
- 502
- 1
- 7
- 23
-
Button inside a view.... – MainakChoudhury Dec 16 '15 at 14:06
-
you need to call layoutIfneeded after you chnage the constraints!!! Look at this answer for more info: http://stackoverflow.com/questions/20609206/setneedslayout-vs-setneedsupdateconstraints-and-layoutifneeded-vs-updateconstra – Teja Nandamuri Dec 16 '15 at 14:16
1 Answers
2
You can create IBOutlet for height constraint of you view and you can change value for it.Just check how to create.
Now use the code below to set height of you UIVIew
heightConstraintOfView.constant = DYNAMIC_HEIGHT;

Anil solanki
- 962
- 4
- 20
-
-
so after making the height of the view as dynamic can i change the frame (view.frame.height). and will a button inside this view automatically get re framed.? – MainakChoudhury Dec 16 '15 at 14:05
-
dont forget to do layoutIfneeded after you change the constraints!!! @Anilsolanki – Teja Nandamuri Dec 16 '15 at 14:08
-
-
You cannot change the frame of view with view.frame.height .It will not effect.But if you will change height by constraint coding as I suggest then you should not fix the UIbutton height.Make it's autolayout without fixed height. – Anil solanki Dec 16 '15 at 14:09
-
My `UIView` frame is (0,0,560,145). Constraints are set accordingly. Now i add a `UIButton` with frame(0,130,100,15)Constraints set (No Ht constraints). So when i dynamically change the ht constraint of the `UIView` by 20. My button does not move up. @Anilsolanki – MainakChoudhury Dec 16 '15 at 14:50