When I use this code:
- (void)viewDidLoad
{
[super viewDidLoad];
CGFloat mainViewWidth = self.view.bounds.size.width;
NSLog(@"%f", mainViewWidth);
}
I got the result in simulator:480
and when i start the app on my iPhone 4 i got the result 320?
Did I do something wrong?
Do the same in viewWillAppear
.
-(void)viewWillAppear:(BOOL)animated{
CGFloat mainViewWidth = self.view.bounds.size.width;
NSLog(@"%f", mainViewWidth);
}
and see if you are getting correct values.. ViewDidLoad
gets called before view is drawn completely. Accessing UIView
size property gives you unpredictable values there.
Swift 3.1 :
let width = yourView.bounds.width
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With