9

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 ?

Oliver
  • 23,072
  • 33
  • 138
  • 230

1 Answers1

14

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.

mvds
  • 45,755
  • 8
  • 102
  • 111