Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a UIView in fullscreen for all Device in iOS Programatically?

Tags:

ios

I have to set an UIView in fullscreen Programatically for all devices like: iPhone 3GS, 4, 4S, 5, 5S, 5C.

I googled so many times and get a answer but its not coming properly. 20 pixel is less from bottom part. I share my screenshot please see and let me know what i have to do.

enter image description here

My Code is :

      UIView  *myview = [[UIView alloc] initWithFrame:CGRectMake(0, 0,   [[UIScreen mainScreen] applicationFrame].size.width, [[UIScreen mainScreen] applicationFrame].size.height)];
      [myview setBackgroundColor:[UIColor grayColor]];
      [self.view addSubview: myview];

See properly from bottom its 20 pixel is white. How can i manage that. ?

like image 467
user3631436 Avatar asked Sep 11 '14 10:09

user3631436


2 Answers

Try this one:

 UIView  *myview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
 [myview setBackgroundColor:[UIColor grayColor]];
 [self.view addSubview:myview];

I'll clarify you properly, i think you can understand.

It's a little bit difference in between [[UIScreen mainScreen] bounds] & [[UIScreen mainScreen] applicationFrame].

When you take UIScreen for it's Bounds you get the whole device screen. (include status bar).There is no relationship between the two calls except that the applicationFrame is returned in the UIScreen bounds coordinate system.

like image 69
Soumya Ranjan Avatar answered Nov 17 '22 16:11

Soumya Ranjan


UIView  *myview = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[myview setBackgroundColor:[UIColor grayColor]];
[self.window addSubview: myview];

 NSLog(@"FRAME: %@",NSStringFromCGRect(myview.bounds));

2014-09-11 12:17:37.451 Test[21793:60b] FRAME: {{0, 0}, {320, 480}}

like image 41
freshking Avatar answered Nov 17 '22 15:11

freshking