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 ...
随机推荐
- RNA分析要点
1. 有参与无参转录组分析 2. lncRNA分析 以RNA-Seq测序技术为基础的转录组测序作为高通量测序时代核心技术之一,已在生物科学及医学领域前沿研究中获得广泛应用.RNA-Seq可进行全基因组 ...
- sys.argv和getopt.getopt()的用法
1.sys.argv Python中sys.argv是命令行参数从程序外部传值的的一种途径,它是一个列表,列表元素是我们想传进去的的新参数,所以可以用索引sys.argv[]来获得想要的值.因为一个写 ...
- 《Just for Fun》---读后感
<Just for Fun>本书是Linux之父林纳斯自传,书名的意思是:只是为了好玩.主要是讲了林纳斯的人生经历,以及Linux的诞生过程.Linux从一个终端仿真器到一个世界瞩目的操作 ...
- Java 关键字有哪些
数据类型: Boolean(布尔型) int long short byte float double char class interface( ...
- XE7 里面添加自定义View
经过xe4,xe5,xe6 这么几个版本的磨合,易博龙终于在今年9月推出了统一的多平台开发版本-XE7. 经过最近几天的测试,非常不错.如果各位同学在做移动开发,强烈建议使用XE7. 前面几个版本可以 ...
- 48 Fixing relationship Problems with Humor 用幽默解决人际关系问题
48 Fixing relationship Problems with Humor 用幽默解决人际关系问题 ①We've all heard that laughter is the best me ...
- Docker mysql启动自动按顺序导入sql
1.目录结构 -rw-r--r-- root root Jan : Dockerfile -rw-r--r-- root root Jan : initdb.sh drwxr-xr-x root ro ...
- underscore utility
1._.noConflict:命名冲突处理方法 _.noConflict = function() { root._ = previousUnderscore; //返回this不错 return t ...
- Python学习-37.Python中的正则表达式
作为一门现代语言,正则表达式是必不可缺的,在Python中,正则表达式位于re模块. import re 这里不说正则表达式怎样去匹配,例如\d代表数字,^代表开头(也代表非,例如^a-z则不匹配任何 ...
- Checkpoint--相关问题
Checkpoint是实例级别还是数据库级别? 答:数据库级别,在SQL Server关闭时,会对所有数据库逐一提交checkpoint 测试代码 USE DB0002 GO CHECKPOINT G ...