0

I am making an application which will run both on iPhone and iPad. On the iPhone the space available is limited so the text size on the labels are "small", however on the iPad the screen size available is larger and therefore I want the labels text size to be increased as well. How can I achieve this?

Example: I have labels that has a text size of 12 points on iPhone, on iPad I may want them to be 26 points.

I thought of making some macros for the preprocessor. Some kind of stylesheet. Each iPhone size has a corresponding iPad size.

(Just for illustrating purpose of what I had in mind)

#define 12 CheckIfIphone then 12 otherwise 26

I let the name of the macro be the text size in point on iPhone, and this would be replaced if the current device is iPad.

LuckyLuke
  • 42,935
  • 77
  • 254
  • 416

2 Answers2

1

You can check out the documentation to read all about detecting the current device, in particular UI_USER_INTERFACE_IDIOM. These questions may also have useful information for you:

  1. API to determine whether running on iPhone or iPad

  2. How does one get UI_USER_INTERFACE_IDIOM() to work with iPhone OS SDK < 3.2

Set a variable fontSize that is determined by the device type and then use [myLabel setFont:[UIFont systemFontOfSize:fontSize]];

Community
  • 1
  • 1
PengOne
  • 47,332
  • 17
  • 126
  • 147
  • the question is not how I check which device it is, but how I can have two different text sizes on the same label based on the device. – LuckyLuke May 28 '11 at 22:47
  • 1
    @Andreas: That's the easy part. See above. You can either check for each label (bad) each view controller (not too bad) or set a global (best). – PengOne May 28 '11 at 22:51
  • I do not understand how this solve my problem. I want a font size of e.g. 14 to be bigger on iPad. – LuckyLuke May 29 '11 at 17:11
  • @Andreas: You **do not** want to change the number 14 to be the number 28. What I'm suggesting is that you define `font14 = (ipad ? 28 : 14)` (no, that's not real code, just an explanation of an idea). Then when you set a font to font14 it will be of size 28 on the ipad and size 14 on the iphone. – PengOne May 29 '11 at 19:35
-2

I would consider using two different stylesheets, something like

ipad.css and iphone.css

Then detect which device you are using and serve the appropriate stylesheet

With this method you could also have a main.css which contains most of the styles that do not change. Each device would get that stylesheet. The device-specific stylesheets would contain only those styles needed bythat device.

Jason Gennaro
  • 32,917
  • 6
  • 59
  • 84