如何在Swift中的plus设备上增加字体和大小? [英] How to increase fonts and sizes on plus device in Swift?

查看:101
本文介绍了如何在Swift中的plus设备上增加字体和大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察到一些流行的应用程序.当我们比较iPhone Plus设备和普通设备时,字体和图像会有所不同. iPhone Plus设备更大一点.我们如何在iOS应用程序中实现相同目标?我已经使用过启动画面.但是字体仍然是相同的,在加号和普通设备上没有区别.

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.

推荐答案

只需为每个控制器创建自定义类.下面,我为UIButton创建csutom类,也可以为其他控件创建该类.

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.

这篇关于如何在Swift中的plus设备上增加字体和大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆