0

I want, in Swift, to have a different code if the device is an iPhone (or iPod) and a different code if it's an iPad. And also a different code if the screen's size is 3,5 or 4,0.

I can do it in Objective-C with this code:

iPhone or iPad:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {}
else {}

But I don't know how I can do these 2 conditions in Swift. The same doesn't work.

Thank's a lot.

Gilles

Steve Wilford
  • 8,762
  • 5
  • 40
  • 66
BoledgiDev
  • 1,168
  • 1
  • 9
  • 11
  • 3
    Please refer similar Stackoverflow question http://stackoverflow.com/questions/24059327/ui-user-interface-idiom-in-swift – Sasi Jun 23 '14 at 13:26
  • Thank's. I've searched but I didn't find this post. – BoledgiDev Jun 23 '14 at 13:39
  • But for the size of the screen there's no answer, have you to an idea ? – BoledgiDev Jun 23 '14 at 18:02
  • Do something like this: let screenSize: CGRect = UIScreen.mainScreen().bounds then you can access the width and height like this: let screenWidth = screenSize.width; let screenHeight = screenSize.height; if you want 75% then do: let screenWidth = screenSize.width * .75; – Sasi Jun 25 '14 at 08:18
  • Thanks a lot and finally how I can do the same in objective-c please ? Thank's for all your help. – BoledgiDev Jun 26 '14 at 14:56
  • CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; – Sasi Jun 27 '14 at 05:19

0 Answers0