Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - getting the size of a view in pixels

I have a camera taken picture, and I'd like to resize it to the exact size of a view. But... bounds.size on an iPhone 4 does not take account of the retina display.

I'd like a code that can give me the real pixel size of the view, so it can work on any device without having to test / to know the kind of hardware it runs on.

Do you know how I may do this ?

like image 298
Oliver Avatar asked Apr 10 '11 22:04

Oliver


1 Answers

Every view has the contentScaleFactor property, which is typically 1.0 (3G, 3GS, iPad) or 2.0 (retina screens). Another approach is to use [[UIScreen mainScreen] scale], which has the same values.

note to remain compatible with iOS versions prior to 4.0, you have to check if the method is available using respondsToSelector:@selector(contentScaleFactor) before getting the value.

like image 63
mvds Avatar answered Oct 30 '22 22:10

mvds