iOS的“设置” –> “显示与亮度” –> “文字大小”,能够修改默认的系统字体大小,当修改以后,系统自带的应用如信息等都会随之改变,手机QQ会随之发生变化:html
而微信的字体大小并不会随系统的字体大小改变而改变,微信本身有设置文字大小的功能,在“我” –> “设置” –> “通用”-> “字体大小”中进行设置react
iOS中若是想作到跟随系统默认的字体大小改变而改变,怎么实现呢,步骤以下:ios
一、设置字体的新式为UIFontTextStyle某个选项;git
二、注册通知,监听字号改号改变时修改字体而后从新更新一下布局;github
- (id)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:style]) {
if (IOS_VERSION >= 7.0)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleContentSizeCategoryDidChanged:) name:UIContentSizeCategoryDidChangeNotification object:nil];
}
}
}
//
- (void)handleContentSizeCategoryDidChanged:(NSNotification *)notification
{
//update font size/frame and view
}
Android默认是跟随系统字体大小改变而改变的,那若是想避免受系统字体大小的影响,如何处理(4.0开始,系统提供修改字体大小功能)?react-native
方法1、将TextView的字体单位由sp改成dp;微信
方法2、在自定义的Activity中重写getResources方法;ide
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration conf = new Configuration();
conf.setToDefaults();
res.updateConfiguration(conf, res.getDisplayMetrics());
return res;
}