Reputation: 65
I have created one UIView inside the UIScrollView from storyboard.
I want to set the frame to UIView programatically. I have tried to set frame using setFrame function programatically, but its not working for the UIView which is inside UIScrollView.
if I create one UIView inside the UIScrollView using [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 110)],and than change size of the view,it is work!
my code:
but I want to create a uiview by IB and set frame using setFrame function.
Most impornatant condition is Autolayout is "TRUE".
Upvotes: 1
Views: 1238
Reputation: 69027
Most impornatant condition is Autolayout is "TRUE".
If you want to mix constraints with setting a view's frame directly, you will need to make sure to set view.translatesAutoresizingMaskIntoConstraints = YES
for your view. AFAIK, this cannot be done in IB for iOS, only in code.
Also beware that setting translatesAutoresizingMaskIntoConstraints = YES
will add new constraints to those you define in IB (or programmatically) and you have to ensure they remain consistent, otherwise you will get an exception. So, e.g., if you set the frame origin in code, but also pinned the top distance between your view and the superview, you will run into problems if those specifications are not compatible.
Upvotes: 3