Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

size of UIView object returned as zero under autolayout

I'm re-writting an app under IOS6 with autolayout but have problems accessing the size of a subclass of UIView

@property (weak, nonatomic) IBOutlet MyView *myView1;

in

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"myView1: %@",self.myView1);
}

The size of the UIView is fully defined in the StoryBoard but comes out as zero when I run the code. Is this todo with auto layout or is the subview simply not defined yet? Am I doing something basically wrong here?

like image 652
drw Avatar asked Jan 03 '13 22:01

drw


1 Answers

Just found one possible answer here. Running the methods

[self.view setNeedsLayout];
[self.view layoutIfNeeded];

forces a calculation of UIViews dimensions causing the expected values to appear in the log and also be known unto the UIView subclass itself.

like image 80
drw Avatar answered Nov 01 '22 00:11

drw