-1

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 ?

MainakChoudhury
  • 502
  • 1
  • 7
  • 23

1 Answers1

2

You can create IBOutlet for height constraint of you view and you can change value for it.Just check how to create.

Creating UIVIew height constraint outlet

Outlet created

Now use the code below to set height of you UIVIew

  heightConstraintOfView.constant = DYNAMIC_HEIGHT;
Anil solanki
  • 962
  • 4
  • 20
  • Need further help then let me know. – Anil solanki Dec 16 '15 at 13:50
  • 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
  • @MainakChoudhury If it has correct authorizes - yes – Taier 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