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 ...
随机推荐
- sql删除重复记录
DELETE E FROM t E where E.id> ( SELECT MIN(X.id) FROM t X WHERE X.name = E.name );
- Binary search tree or not
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- 594. Longest Harmonious Subsequence
方法一:用一个map来辅助,代码简单,思路清晰 static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }( ...
- hadoop学习笔记(二):centos7三节点安装hadoop2.7.0
环境win7+vamvare10+centos7 一.新建三台centos7 64位的虚拟机 master node1 node2 二.关闭三台虚拟机的防火墙,在每台虚拟机里面执行: systemct ...
- CentOS中的一些小技巧和特殊知识
一:软件: firefox 1.在tab栏右键可以打开上一次关闭的标签. 2.在上面的搜索栏可以添加搜索引擎,这样就不需要再打开标签页访问搜索引擎主页来搜索了. 3.获取firefox下载弹框的资源U ...
- excel绝对引用中间添加符号
=F1&"_"&J1 绝对引用 相对引用 按F4 然后复制全部,选择性黏贴,值和数字即可
- 20155218 2016-2017-2 《Java程序设计》第8周学习总结
20155218 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 java.util.logging包提供了日志功能相关类与接口,不必额外配置日志组件,就可以 ...
- DOM数据解析
//DOM : Document Object Model ,一种XML解析的方式,先读取整篇的内容,然后再进行解析,解析速度比较快,如果内出现错误,解析就会失败,iOS不支持DOM解析,goole提 ...
- Visual C++中的ADO编程
摘 要:本文介绍了微软推出的以ActiveX技术为基础的ADO数据存取技术,分析了ADO的工作原理,并用Visual C++说明了ADO数据访问技术的实现方法. 关键字:ADO:连接对象:OLE D ...
- spring案列——xml配置
一.需要的jar包 spring.jar(官网下载) commons-logging.jar 二.项目结构 三.entity(实体类) package com.team.model; public c ...