如何在不同的 iPhone 中更改 uilabel 文本大小 [英] how to change uilabel text size in different iPhones

查看:18
本文介绍了如何在不同的 iPhone 中更改 uilabel 文本大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法针对不同的屏幕尺寸更改 UILabel 文本大小?

Is there a way to change UILabel text size for different screen sizes?

我需要在 I-phone 6 和 6+ 中将文本放大.

I need the text to be bigger in I-phone 6 and 6+.

我可以这样做吗?

这样做的正确方法是检查屏幕高度,然后更改文本大小吗?

Would the correct way to do this will be to check screen height and then changing the text size?

谢谢

推荐答案

在 .pch 文件中声明以下内容

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

这篇关于如何在不同的 iPhone 中更改 uilabel 文本大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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