开发者

One text size for iPhone and another one for iPad

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", howev开发者_如何学Goer 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.


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]];


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜