I am making an universal application for iPhone and iPad. I know there is a option to define that the text should scale downwards to a chosen point-size when it is to large however I need the text to开发者_开发百科 scale upwards when the text is shown on the iPad. Is that possible? I have a label with a size of 18 points. This almost occupy the whole width on the iPhone with the length of the text in consideration. But on iPad this will not be the case because of the increased size of the screen...
Thank you for your time.
I had the same issue on a universal App.
I did set the autosizing parameters to scale all components directly in Interface Builder but it wasn't scaling the font size to take the newly given screen space.
I ended up updating the viewDidLoad
of each view with the code below, basically iterating through the component of the view and doubling the pointSize for all labels (can do as well for buttons):
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
for (UIView *component in self.view.subviews) {
if ([component isKindOfClass:[UILabel class]]) {
UILabel *labelToUpdate = (UILabel *) component;
[labeltoUpdate setFont:[labelToUpdate.font fontWithSize:labelToUpdate.font.pointSize*2]];
}
}
The app does scale up nicely from iPhone to iPad now.
You could loop on the method:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
until you get a match that takes up two lines, then use the previous font-size. Seems quicker/easier to just use idioms to define a specific size for the iPad.
精彩评论