How to increase fonts and sizes on plus device in Swift?

3.9k Views Asked by At

I observed some popular apps. When we compare iPhone Plus devices and normal devices, fonts and images are varying. A little bit bigger in iPhone Plus device. How can we achieve same in our iOS applications? I already used splash screens. But still fonts are same, no difference in plus and normal devices.

Note: By resolution differentiate in coding is working fine. But I'm looking for other alternative ways like either in adaptive layouts nor launch screens.

3

There are 3 best solutions below

5
Ketan Parmar On

You can do it withing your interface builder(xib or storyboard)!

Select your label or text field etc and go to attribute inspector.

Near font you will find + button, click it, select your variation (size class) and set different font for that particular size class.

Refer below screenshot for better understanding,

enter image description here

Reference : Size classes in Interface Builder in Xcode 8

For example Compact width, Regular height this variation or size class is for all iphones in portrait mode!

you can refer Apple documentation for more details about size classes!

Second thing you can do that is set autoshrink to minimum font scale and set that font scale between 0 to 1.

and then set larger font(maximum font size that you want to show in plus or pro devices for your app) in your interface builder. Now, when your app will get open in small size device, your font size will be try to reduce with that minimum scale factor. for example if you have set scale factor 0.5 and your font size is 100 in storyboard then in small device it will try to reduce font size till 50 to fit in label or textfield.

enter image description here

0
Hitesh Surani On

Just create custom class for each controller. Below, I am create csutom class for UIButton, You can also create same for other control.

HSCustomButton.h

#import <UIKit/UIKit.h>

@interface HSCustomButton : UIButton

@end

HSCustomButton.m

#import "HSCustomButton.h"
#define SCALE_FACTOR_H ([UIScreen mainScreen].bounds.size.height / 667) 


@implementation HSCustomButton

- (id)initWithCoder:(NSCoder *)aDecoder {
    if( (self = [super initWithCoder:aDecoder]) ){
        [self layoutIfNeeded];
        [self configurefont];
    }
    return self;
}

- (void) configurefont {
    CGFloat newFontSize = (self.titleLabel.font.pointSize * SCALE_FACTOR_H);
    self.titleLabel.font = [UIFont fontWithName:self.titleLabel.font.fontName size:newFontSize];
}
@end

Just change class name in storyboard, then font scale automatically for all other device.

0
Datt Patel On

Create category class of UILabel or any other control (UIButton , UITextField , etc).

UILabel+DynamicFontSize.h

 #import <UIKit/UIKit.h>

 @interface UILabel (DynamicFontSize)
 @property (nonatomic) IBInspectable BOOL adjustFontSize;
 @end

UILabel+DynamicFontSize.m

 #import "UILabel+DynamicFontSize.h"

 @implementation UILabel (DynamicFontSize)
 @dynamic adjustFontSize;
 -(void)setAdjustFontSize:(BOOL)adjustFontSize{
     if (adjustFontSize)
     {
        CGRect screenBounds = [[UIScreen mainScreen] bounds];
        self.font = [self.font fontWithSize:self.font.pointSize*(screenBounds.size.width/320)]; // 320 for iPhone 5(320x568) storyboard design
        // if you design with iphone 6(375x667) in storyboard, use 375 instead of 320 and iphone 6 plus(414x736), use 414
     }
   }
 @end

Usage

Select any label and find property name Adjust Font Size change value to ON

enter image description here