Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8 return height= 1000 and Width =1000 for UIview (actual size is (328,40))

Since i installed Xcode 8, i am in trouble. I didnt get the correct value for each or any UIView.

I also got the constraint alert for UIView. So i update it. But view returns 1000 as width or height. I tried or search a lot. But didnt got any proper solution. pls help me.

like image 979
Sommm Avatar asked Sep 20 '16 13:09

Sommm


2 Answers

As mentioned here, you should call layoutIfNeeded for your view in viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.view layoutIfNeeded];

    // Now all your subviews are sized as you expect
}
like image 178
silvansky Avatar answered Nov 18 '22 17:11

silvansky


For Swift 3 :

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.layoutIfNeeded()
}
like image 34
Van Avatar answered Nov 18 '22 15:11

Van