Search code examples
iosuiviewframecgrectcgrectmake

Change a UIView Frame


I have set a UIView in my storyboard and make it an outlet.

 @property (nonatomic, weak) IBOutlet UIView *testView;

In the - (void)viewDidLoad method, I want to change its frame like this

CGRect frame = self.testView.frame;
frame.size.height = 2;
self.testView.frame = frame;

But it does not work. Anybody can tell me why?


Solution

  • You might enabled the autolayout in your project , if so the setFrame straightly won't work . Check here for more info

    Solution :

    • Disable the autolayout, if you don't need any more
    • Check the above link using with the autolayout .