Dynamic Type
啥是 Dynamic Type
动态字体,即视力不好的用户,调整了默认字体的大小,开发者应该根据这个设置,动态改变界面的字体等,保证用户能看得清楚。
这个还是蛮重要的,视力不好的人越来越多。
用户在哪里调整

打开了开关之后,底部明显调整更大了。

开发者怎么知道用户设置了多大的字体
通过监听一个通知即可
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIContentSizeCategoryDidChange, object: .none, queue: OperationQueue.main) { (notify) in
let aa: UIContentSizeCategory = notify.userInfo?[UIContentSizeCategoryNewValueKey] as! UIContentSizeCategory
print(aa)
}
可以有很多种

如何自动调整 Lable 的大小
使用 StoryBoard
- font 指定为某种 style
 选择 Automatically Adjusts Font
使用代码
label.font = UIFont.preferredFont(forTextStyle: .title2)
label.adjustsFontForContentSizeCategory = true
label.firstBaselineAnchor.constraintEqualToSystemSpacingBelow(storyLable.lastBaselineAnchor, multiplier: 1).isActive = true
label.centerXAnchor.constraint(equalTo: storyLable.centerXAnchor).isActive = true
效果如下

为自定义字体自动缩放
let fontName = "Futura-MediumItalic"
guard let customFont = UIFont.init(name: fontName, size: UIFont.labelFontSize) else {
print("not found font \(fontName)")
return
}
let customLabel = UILabel.init()
customLabel.font = UIFontMetrics.default.scaledFont(for: customFont)
为视障患者提供大图片
各种 bar (底部 tabbar、顶部导航栏)
因为 bar 大小固定,苹果提供了一种方式,长按时,放大显示。

使用storyboard
有两种方式使用向量版本的图片,保证缩放信息
同时制定一个大图 (75 pt) 和一个小图

使用代码
使用largeContentSizeImage属性。self.tabBarItem.image = UIImage.init(imageLiteralResourceName: "layoutsmall")
self.tabBarItem.largeContentSizeImage = UIImage.init(imageLiteralResourceName: "layoutbig")
一般图片
使用 storyboard
使用代码
imageView.adjustsImageSizeForAccessibilityContentSizeCategory = true
其他技巧
- number of lines 设为 0
这样子大字号时,可以不被截断 文字之间布局时,使用系统提供的间距
customLabel.firstBaselineAnchor.constraintEqualToSystemSpacingBelow(label.lastBaselineAnchor, multiplier: 1).isActive = true
使用缩放后的值
frame.origin.y += UIFontMetrics.default.scaledValue(for: 40.0)
根据不同的 Text Size 采用不同的布局

感觉这个也不咋智能。

比如不同的文字大小,布局是不同的。
参考
Dynamic Type的更多相关文章
- 理解iOS 8中的Self Sizing Cells和Dynamic Type
http://www.cocoachina.com/ios/20140922/9717.html 在iOS 8中,苹果引入了UITableView的一项新功能--Self Sizing Cells,对 ...
- Working with the Dynamic Type in C#
Working with the Dynamic Type in C# https://www.red-gate.com/simple-talk/dotnet/c-programming/workin ...
- iOS Programming Dynamic Type 2
iOS Programming Dynamic Type 2 You will need to update two parts of this view controller for ...
- iOS Programming Dynamic Type 1
iOS Programming Dynamic Type 1 Dynamic Type is a technology introduced in iOS 7 that helps realize ...
- Dynamic type checking and runtime type information
动态类型的关键是将动态对象与实际类型信息绑定. See also: Dynamic programming language and Interpreted language Dynamic type ...
- Dynamic V Strongly Typed Views
Come From https://blogs.msdn.microsoft.com/rickandy/2011/01/28/dynamic-v-strongly-typed-views/ There ...
- 关于type check的定义
Concept: Type Checking There is no static type checking in Scheme; type checking is done at run time ...
- C# 动态语言特性,dynamic 关键字研究
1 动态语言简介 支持动态特性的语言现在大行其道,并且有继续增长的趋势.比如 Ruby 和 Python, 还有天王级的巨星 --- JavaScript. 现在一个程序员说自己对 Jav ...
- Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical
http://julialang.org/ julia | source | downloads | docs | blog | community | teaching | publications ...
随机推荐
- windows 安装配置jdk7
1.安装jdk这里不在介绍 2.配置新建用户变量:JAVA_HOME 值为(就是你自己jdk的安装路径):C:\Program Files\Java\jdk1.7.0_75\ 3.配置系统变量:Pat ...
- echarts 使用配置模式(含事件)
<!-- 引入echarts UMD 环境--> <script src="js/echarts/build/dist/echarts.js"></s ...
- 面向对象先修:Java入门
学习总结 在C语言和数据结构的基础上,在上暑期的面向对象Java先修课程时,熟悉语言的速度明显加快了很多.Java和C在很多基础语法上非常相似,比如基本的数据类型,循环以及条件分支语句,数组的遍历等. ...
- 2018.09.09 bzoj3505: [Cqoi2014]数三角形(容斥原理+简单计数)
传送门 正难则反. 可以直接把问题转化成求出三点共线的情况数量. 如果同在一排或一列显然可以直接算,关键是如何求出斜着的. 我们知道,对于一个整点矩形. 如果长为x,宽为y,那么这个矩形任意一条对角线 ...
- Cygwin工具的简单使用
简介 从使用角度来看:Cygwin就是一个windows软件,该软件就是在windows上仿真linux操作系统.简言之,cygwin是一个在windows平台上运行的 linux模拟环境,使用一个D ...
- 一致性哈希Java源码分析
首次接触一致性哈希是在学习memcached的时候,为了解决分布式服务器的负载均衡或者说选路的问题,一致性哈希算法不仅能够使memcached服务器被选中的概率(数据分布)更加均匀,而且使得服务器的增 ...
- SQL之mysql常用操作语句(入门级)
1.进入数据库: mysql -u root -p mysql -h localhost -u root -p database_name 2.列出数据库 show databases; 3.选择数据 ...
- 解决sea_born和matplotlib画图中文显示的问题
#以下解决mtpl中文显示问题 from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei'] #以下解决seaborn中文编码报错问 ...
- Linux 系统运维常用命令
1 文件管理2 软件管理3 系统管理4 服务管理5 网络管理6 磁盘管理7 用户管理8 脚本相关9 服务配置==================================------------ ...
- MFC框架仿真<二>