Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container View made in Storyboard will not change frame programmatically

I have a container view, @property (weak, nonatomic) IBOutlet UIView *containerView;, but it won't move when I set its frame. Here is how I am trying:

- (void)setFramesForCategories
{
    CGRect frame = _containerView.frame;
    frame.origin.x = 20;
    frame.origin.y = self.view.frame.size.height - 52;
    frame.size.width = 236;
    frame.size.height = 60 * [[_dataDict objectForKey:@"Key"] count];
    _containerView.frame = frame;
}

I know this is basic and it has worked for me before, when I was moving programmatically created objects, but it is not working for me now.

like image 750
Patrick Veilleux Avatar asked Dec 04 '22 13:12

Patrick Veilleux


1 Answers

The problem I had was the constraints set up in Storyboard were overriding the frame change. This explains why I wasn't having the same issues with programmatically added objects. All I had to do to turn off constraints for the project was to go to the Storyboard.storyboard file, then make sure the "Utilities" sidebar is open and select the "File Inspector" tab. Then I scrolled down under "Interface Builder Document" and deselected "Use Autolayout." After this, I reran the the project to find setting the frame programmatically did work.

like image 152
Patrick Veilleux Avatar answered Dec 11 '22 11:12

Patrick Veilleux