1

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?

bohan
  • 1,659
  • 3
  • 17
  • 29

4 Answers4

2

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 .
Community
  • 1
  • 1
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
0

Look at the tiny circle to the left of the property. Is it filled in or hollow? If it's hollow, then it means that you have not connected this particular element of the storyboard to the file's owner.

If the circle is filled in, than the outlet IS connected to something on your storyboard. Just make sure it's connected to the right entity, namely the UIViewController (or subclass thereof) that you are declaring testView within.

ryan cumley
  • 1,901
  • 14
  • 11
0

Assuming its connected to your XIB do the following after changing the view -

[self.view setNeedsDisplay];
Paulo
  • 1,245
  • 10
  • 8
0

Trying changing the height to high number and see if that make a difference. I have created demo project for changing and reverting the height. Hope this helps.

https://github.com/rshankras/StackOverflowUIView

rshankar
  • 3,045
  • 2
  • 18
  • 19
  • I know if it happens in a new IBAction it works, but I want to change the frame in the method - (void)viewDidLoad – bohan Mar 20 '14 at 04:17
  • ViewDidLoad gets called even before the View is drawn and hence you don't see the change. You can place the code in layoutSubviews? – rshankar Mar 20 '14 at 04:24