6

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. ?

user3631436
  • 459
  • 2
  • 5
  • 10

2 Answers2

9

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.

Soumya Ranjan
  • 4,817
  • 2
  • 26
  • 51
  • This will make the new view full-screen in terms of _size_, but it will position it respective to the top-left corner of `self.view`, which **may not be the top-left corner of the screen**. – Nicolas Miari Dec 10 '18 at 04:27
  • Could someone show the swift equivalent for this one? – Arjun Oct 06 '19 at 07:24
1
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}}

freshking
  • 1,824
  • 18
  • 31