啥是 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. process_进程池

    from multiprocessing import Poolimport os,timeimport multiprocessingdef func(msg): print("msg:& ...

  2. 高性能 js -- 无阻塞加载脚本

    参考: <<高性能JavaScript>> Nicbolas C. Zakas 著 javascript代码的下载和执行过程会阻塞浏览器的其他进程, 比如页面的绘制, 遇到&l ...

  3. 8.7 使用索引-notes

    七 正确使用索引 一 索引未命中 并不是说我们创建了索引就一定会加快查询速度,若想利用索引达到预想的提高查询速度的效果,我们在添加索引时,必须遵循以下问题 1 范围问题,或者说条件不明确,条件中出现这 ...

  4. MVC, EF, Code First 相关问题总结

    1. 控制表名单复数: 在DbContext类中修改OnModelCreating()为: protected override void OnModelCreating(DbModelBuilder ...

  5. (动态规划 01背包 打印路径) CD --UVA --624

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87813#problem/G 每个CD的时间不超过 20没有哪个CD的时间是超过N ...

  6. MFC自动生成代码详解(一)

    首先声明这篇博客是给MFC刚刚上路的coder准备的,老鸟们就自觉无视我吧! 大家有没有感觉,创建MFC工程时他总会生成一大堆文件一大堆代码.虽然给我们带来了便利,但是调试的时候碰到这些代码总是畏首畏 ...

  7. 从0学习JQ

    转 张子秋的博客 为以后用到的时候好查询! 从零开始学习jQuery (一) 开天辟地入门篇 从零开始学习jQuery (二) 万能的选择器 从零开始学习jQuery (三) 管理jQuery包装集 ...

  8. linux环境下(非UI操作)所有软件的安装与卸载总结

    UI界面的软件管理 linux下的软件一般都是经过压缩的,主要的格式有这几种:rpm.tar.tar.gz.tgz等.所以首先拿到软件后第一件事就是解压缩. 在xwindow下以rpm格式的软件安装比 ...

  9. PHP 7 安装 Memcache 和 Memcached 总结

    Memcache 与 Memcached 的区别 Memcached 是 Memcache 的升级版,优化了 Memcache,并增加了一些操作方法.所以现在基本都是用最近版本的. PHP 7 下安装 ...

  10. [jquery-ajax] jquery ajax 三种情况对比

    <button class="btn1">async:false</button> <button class="btn2"> ...