Is there a way to change UILabel text size for different screen sizes?
I need the text to be bigger in I-phone 6 and 6+.
Can i do this?
Would the correct way to do this will be to check screen height and then changing the text size?
Thanks
if (self.view.frame.size.width == 320){
//iPhone 2G, 3G, 3GS, 4, 4s, 5, 5s, 5c
label.font = UIFont(name: "....", size: 20)
}
else if (self.view.frame.size.width == 375){
//iPhone 6
label.font = UIFont(name: "....", size: 25)
}
else if (self.view.frame.size.width == 414){
//iPhone 6 Plus
label.font = UIFont(name: "....", size: 30)
}
In the .pch file declare the following
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
Use the following where you need to implement
if (IS_IPHONE_6){
[myLabel setFont:[UIFont fontWithName:@"FontName" size:18]];
}
else if (IS_IPHONE_6P){
[myLabel setFont:[UIFont fontWithName:@"FontName" size:20]];
}
There are convenience methods to determine the height of the current device from a library called Resplendent Utilities. You will first have to install the cocoa pod for this library here http://cocoapods.org/pods/ResplendentUtilities. If you can't install cocoa pods, you can simply get the needed code from the github link to this library https://github.com/Resplendent/ResplendentUtilities.
Once you have this library in your project, import this file https://github.com/Resplendent/ResplendentUtilities/blob/master/Pod/Classes/ResplendentUtilities/Code/ResplendentUtilities/Misc/Compatability/RUScreenSizeToFloatConverter.m
Once you have this file imported, init the class object of this file (RUScreenSizeToFloatConverter). You can then store the appropriateHeightForCurrentScreenHeight property of this class in a CGFloat. This property gives you the height of your current device. You can then use some conditional statements (if (appropriateHeightForCurrentScreenHeight == 736.0f) {}) to determine the size of your label text depending on the height of your device.
if (IS_IPHONE6) { [myLabel setFont:[UIFont fontWithName:@"digital-7" size:20]]; else if (IS_IPHONE6_PlUS) [myLabel setFont:[UIFont fontWithName:@"digital-7" size:30]]
– Chlebta