Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

self.view.bounds.size.width return wrong value

I am facing a very strange problem now. Getting [[self view] bounds].size.width always 320 it's not changing according to the device. iPhone 5, 6 & 6 Plus for all it's return 320.000000 in below all methods.

- (void)viewDidLoad 
{
    [super viewDidLoad];
    NSLog(@"%f", [[self view] bounds].size.width);
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"%f", [[self view] bounds].size.width);
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"%f", [[self view] bounds].size.width);
}

Output

2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000 
2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000
2015-02-11 14:48:03.783 MyApp[2948:86285] 320.000000

Even the splash screen are also there.

How can I get actual size of the view?

like image 231
Tapas Pal Avatar asked Feb 11 '15 06:02

Tapas Pal


1 Answers

Use

NSLog(@"%f", [[UIScreen mainScreen] bounds].size.width);

instead of

NSLog(@"%f", [[self view] bounds].size.width);

It gives u expected w/h.

like image 116
Gajendra K Chauhan Avatar answered Sep 20 '22 19:09

Gajendra K Chauhan