啥是 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

  1. font 指定为某种 style
  2. 选择 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 大小固定,苹果提供了一种方式,长按时,放大显示。

  1. 使用storyboard
    有两种方式

    1. 使用向量版本的图片,保证缩放信息

    2. 同时制定一个大图 (75 pt) 和一个小图

  2. 使用代码
    使用 largeContentSizeImage 属性。

    self.tabBarItem.image = UIImage.init(imageLiteralResourceName: "layoutsmall")
    self.tabBarItem.largeContentSizeImage = UIImage.init(imageLiteralResourceName: "layoutbig")

一般图片

  1. 使用 storyboard

  2. 使用代码

    imageView.adjustsImageSizeForAccessibilityContentSizeCategory = true

其他技巧

  1. number of lines 设为 0
    这样子大字号时,可以不被截断
  2. 文字之间布局时,使用系统提供的间距

    customLabel.firstBaselineAnchor.constraintEqualToSystemSpacingBelow(label.lastBaselineAnchor, multiplier: 1).isActive = true
  3. 使用缩放后的值

    frame.origin.y += UIFontMetrics.default.scaledValue(for: 40.0)
  4. 根据不同的 Text Size 采用不同的布局


    感觉这个也不咋智能。

    比如不同的文字大小,布局是不同的。

参考

Dynamic Type的更多相关文章

  1. 理解iOS 8中的Self Sizing Cells和Dynamic Type

    http://www.cocoachina.com/ios/20140922/9717.html 在iOS 8中,苹果引入了UITableView的一项新功能--Self Sizing Cells,对 ...

  2. 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 ...

  3. iOS Programming Dynamic Type 2

    iOS Programming Dynamic Type  2       You will need to update two parts of this view controller for ...

  4. iOS Programming Dynamic Type 1

    iOS Programming Dynamic Type 1  Dynamic Type is a technology introduced in iOS 7 that helps realize ...

  5. Dynamic type checking and runtime type information

    动态类型的关键是将动态对象与实际类型信息绑定. See also: Dynamic programming language and Interpreted language Dynamic type ...

  6. Dynamic V Strongly Typed Views

    Come From https://blogs.msdn.microsoft.com/rickandy/2011/01/28/dynamic-v-strongly-typed-views/ There ...

  7. 关于type check的定义

    Concept: Type Checking There is no static type checking in Scheme; type checking is done at run time ...

  8. C# 动态语言特性,dynamic 关键字研究

    1       动态语言简介 支持动态特性的语言现在大行其道,并且有继续增长的趋势.比如 Ruby 和 Python, 还有天王级的巨星 --- JavaScript. 现在一个程序员说自己对 Jav ...

  9. 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 ...

随机推荐

  1. 20145226夏艺华 《Java程序设计》第8周学习总结

    教材学习内容总结 学习目标 了解NIO 会使用Channel.Buffer与NIO2 会使用日志API.国际化 会使用正则表达式 了解JDK8增强功能 第14章 NIO与NIO2 14.1 认识NIO ...

  2. 2018.10.23 vijo1243生产产品(单调队列优化dp)

    传送门 这道单调队列真的有点难写啊. 方程感觉挺简单的. f[i][j]f[i][j]f[i][j]表示在第iii个车间结束前jjj次步骤的最小代价. 然后用单调队列毒瘤优化一下就行了. 代码: #i ...

  3. 微信小程序 发送模版消息

    微信小程序开发之发送模板消息 1,小程序wxml页面form表单添加 report-submit="true" <form bindsubmit="sub" ...

  4. 25. Green Living 绿色生活

    25. Green Living 绿色生活 ①We all know that humans are damaging the environment,but what can we do about ...

  5. 【Unity】2.1 初识Unity编辑器

    分类:Unity.C#.VS2015 创建日期:2016-03-26 一.简介 本节要点:了解Unity编辑器的菜单和视图界面,以及最基本的操作,这是入门的最基础部分,必须掌握. 二.启动界面 双击桌 ...

  6. TabHost实现通话记录界面

    //MainActivity.java   public class MainActivity extends TabActivity   {       @Override       public ...

  7. mysql中要根据某个逗号分割的字符串关联查询另一张表的数据

    首先观察下面的查询 select * from company where f_id in ('210','205','208') select * from company where f_id i ...

  8. Dalvik虚拟机java方法执行流程和Method结构体分析

    Method结构体是啥? 在Dalvik虚拟机内部,每个Java方法都有一个对应的Method结构体,虚拟机根据此结构体获取方法的所有信息. Method结构体是怎样定义的? 此结构体在不同的andr ...

  9. Lucene 中自定义排序的实现

    使用Lucene来搜索内容,搜索结果的显示顺序当然是比较重要的.Lucene中Build-in的几个排序定义在大多数情况下是不适合我们使用的.要适合自己的应用程序的场景,就只能自定义排序功能,本节我们 ...

  10. 建立多人协作git仓库/git 仓库权限控制(SSH)

    转载文章请保留出处  http://blog.csdn.net/defeattroy/article/details/13775499 git仓库是多人协作使用的,可以基于很多种协议,例如http.g ...