0

I want to set the width and height of frame programmatically which should vary with the type of Phone like for iphone5 i have made following settings

_splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

But if i install the app in iphone6 the splashview does not fit properly. so i want to set the values of width and height programmatically so that it can be used with any type of phone.

something like:

_splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
Junior Bill gates
  • 1,858
  • 4
  • 20
  • 33
  • did you make any effort to search for this yourself? – Simon McLoughlin Apr 14 '15 at 08:41
  • 2
    While this question is a duplicate you should really be using auto-layout to do this. – Wain Apr 14 '15 at 08:44
  • You should really have separate images to cope with the different pixel resolutions and also aspect ratios. Otherwise your screens will be pixelated or warped depending how you fit the image into the bounds. – Rory McKinnel Apr 14 '15 at 09:13
  • Always use [UIScreen mainScreen].bounds; to get the screen dimensions if you plan on doing it programmatically. – Rohan Bhale Apr 14 '15 at 09:14

1 Answers1

1

You can use UIScreen's bounds property for this, which provides a CGRect with the size that you need:

_splashView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];

You can also set distance constraints on four sides of _splashView to zero to make the view resize with the screen automatically.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523