Search code examples
ios6xcode4.5autolayout

Autolayout+UIView+Its subview


I have a UIView and it has another UIView and some UIButtons as sub view.I gave vertical constraint to my view and last UIButton.Those UIButtons are one after the other vertically designed like radio buttons and then UIView.I able to get nice design when all UIButtons and UIView are displayed one after the other.I have the issue when I need the UIView to be displayed after first UIButton and make other UIButtons hidden.No change is there in design except a big gap between UIView and first UIButton. Thanks in advance for a solution.


Solution

  • We need to use the following code in order to remove constraint that has for the sub-view and last UIButton: [view_object removeConstraint:constraint_object];.After that we have to add constraint to the view and your first button.There are many ways to add constraint but as per your requirement, this is the code [view_object addConstraint:[NSLayoutConstraint constraintWithItem:sub-view_object attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:button_object attribute:NSLayoutAttributeBottom multiplier:1.0 constant:10]];.