Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use different images, depending on iOS device type?

I want to use different images in my iPhone application, depending on whether the current device is an iPhone 3G, iPhone 4, or iPad. I've tried getting the screen resolution (size) of the device, but it always returns 320 X 480 for the different iPhones.

How do I determine which type of device I'm running on so that I can provide the correct images?

I do not want to get the iPhone OS version.

like image 439
Mitesh Khatri Avatar asked Jan 31 '11 20:01

Mitesh Khatri


3 Answers

There's most likely no need to do what you're attempting to do, as iOS has built in support for loading images at the appropriate size for the iPhone (retina and pre-retina resolutions) and iPad.

Read the Resource Programming Guide (specifically the "Specifying High-Resolution Images in iOS" and "iOS Supports Device-Specific Resources" section) and the iOS Application Programming Guide for more information.

Incidentally, both the pre and post retina iPhone/Pods have a point resolution of 320 X 480. Apple distinguishes between point sizes (resolution independent) and pixel size to help things along the way.

like image 53
John Parker Avatar answered Sep 28 '22 03:09

John Parker


If you want this info for the purposes of selecting the proper graphics for your resolution, then middaparka's answer is what you're looking for.

However, if you happen to need device model or resolution info for a different purpose, then UIDevice and UIScreen may be what you want.

NSString *myDeviceModel = [[UIDevice currentDevice] model];
CGRect    myScreenSize  = [[UIScreen mainScreen] bounds].size;
like image 37
macserv Avatar answered Sep 28 '22 04:09

macserv


i think below one solve my problem

https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m

Thanks

like image 38
Mitesh Khatri Avatar answered Sep 28 '22 04:09

Mitesh Khatri