ShannonChenCHN / iOSDevLevelingUp

A journey of leveling up iOS development skills and knowledge.
365 stars 105 forks source link

屏幕渲染机制 #44

Open ShannonChenCHN opened 7 years ago

ShannonChenCHN commented 7 years ago

延伸阅读

ShannonChenCHN commented 6 years ago

Proportional Fonts VS. Monospace Fonts

问题

在使用 UILabel 显示 “01:11:10” 这种数字时,数字 1 的宽度和数字 0 的宽度不同。

解决办法

方法一

iOS 9.0 以前,可以通过设置 font family 为某些特殊字体,来实现 monospace 的效果:

UIFont(name:"Courier", size: 17)

iOS 9.0 及以后,UIFont 新增了 monospace 的 API:

+[UIFont monospacedDigitSystemFontOfSize: weight:]

方法二

让设计师专门设计一套数字 iconfont

方法三

单独为每个数字添加固定宽度的 label

参考

ShannonChenCHN commented 4 years ago

iconfont

相关专题:NSString 和 Unicode

参考资料