uifontdescriptor

Displaying proportionally spaced numbers (instead of monospace / tabular) on iOS

纵然是瞬间 提交于 2019-12-21 04:32:13
问题 I am rendering numbers in iOS (targeting 7 and up) by storing them in an NSAttributedString and rendering with "drawAtPoint:". I am using Helvetica Neue. I have noticed that digits of numbers drawn like this are not proportional – the glyphs all have the same width. Even a skinny "1" takes up the same space as a "0". A test confirms this: for(NSInteger i=0; i<10; ++i) { NSString *iString = [NSString stringWithFormat: @"%d", i]; const CGSize iSize = [iString sizeWithAttributes: [self

A better way to use Dynamic Type with a custom font in Swift 3/iOS10

只谈情不闲聊 提交于 2019-12-20 12:39:04
问题 I tried two ways: Method 1: label.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) label.adjustsFontForContentSizeCategory = true This works fine, even when the preferred text size is changed in the Settings, the text size changes automatically, even before when I go back to the app. But it only works with the system font (San Francisco). Method 2: To use a custom font, I add an extension to UIFontDescriptor : //from this answer http://stackoverflow.com/a/35467158/2907715

iOS文本布局探讨之二——关于TextKit框架中的字体描述

走远了吗. 提交于 2019-12-10 13:54:32
iOS文本布局探讨之二——关于TextKit框架中的字体描述 一、引言 UIFont是iOS开发中处理文本字体的类,关于UIFont的相关内容,以前的一篇博客有详细介绍,本片博客主要介绍关于动态字体的应用与字体描述类NSFontDescriptor的应用。 UIFont应用介绍: http://my.oschina.net/u/2340880/blog/397115 。 二、iOS系统中的动态字体 所谓动态字体,是指在应用使用中,用户可以动态调整字体的风格字号等。在iOS7及之后的iOS系统版本,TextKit框架中提供了一个新的类UIFontDescriptor。简单理解,UIFontDescriptor类是专门用来描述字体的,其中提供了许多方法可以直接创建出某种字体,也可以对字体进行设置和调整。动态字体也由这个类来创建。 在iOS7之后,系统增加了动态字体的功能,当用户在系统设置中修改字体的属性或者字号时,不仅会影响系统应用的字体,第三方应用的字体也可以进行相应调整。系统设置字体界面如下: 使用UIFontDescriptor类中的如下方法可以创建动态字体: //创建动态字体的字体描述类实例 + (UIFontDescriptor *)preferredFontDescriptorWithTextStyle:(NSString *)style;

Using the fontWithSize API with San Francisco

二次信任 提交于 2019-12-08 03:08:09
问题 The new San Francisco fonts in iOS 9 are optimized for the size it will be used at, by adjusting tracking and dynamically switching between SF Display and SF Text. It was noted in the WWDC session #804 developers should not use San Francisco by attempting to initialize a UIFont using fontWithName , for example: UIFont *originalFont = [UIFont systemFontOfSize:11]; UIFont *newFont = [UIFont fontWithName:originalFont.fontName size:44]; This is because the system cannot optimize the font for the

Using the fontWithSize API with San Francisco

和自甴很熟 提交于 2019-12-06 10:36:18
The new San Francisco fonts in iOS 9 are optimized for the size it will be used at, by adjusting tracking and dynamically switching between SF Display and SF Text. It was noted in the WWDC session #804 developers should not use San Francisco by attempting to initialize a UIFont using fontWithName , for example: UIFont *originalFont = [UIFont systemFontOfSize:11]; UIFont *newFont = [UIFont fontWithName:originalFont.fontName size:44]; This is because the system cannot optimize the font for the new size when using the fontWithName API. Instead it was recommended to get the UIFontDescriptor from

Font Descriptor returns nil in iOS 8

拟墨画扇 提交于 2019-11-28 12:21:42
The following code works fine in iOS 7, but doesn't return bold or italic font in iOS 8. It is ok for Helvetica Neue, but doesn't work for Arial font. UIFontDescriptor *descriptor1 = [UIFontDescriptor fontDescriptorWithFontAttributes:@{UIFontDescriptorFamilyAttribute: @"Arial"}]; UIFontDescriptor* boldFontDescriptor1 = [descriptor1 fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; UIFont* font1 = [UIFont fontWithDescriptor:boldFontDescriptor1 size:16.0]; [self.lblArialB setFont:font1]; Tested on device and simulator and still same error. FWIW, this is the workaround I came up with,

Font Descriptor returns nil in iOS 8

↘锁芯ラ 提交于 2019-11-27 06:56:33
问题 The following code works fine in iOS 7, but doesn't return bold or italic font in iOS 8. It is ok for Helvetica Neue, but doesn't work for Arial font. UIFontDescriptor *descriptor1 = [UIFontDescriptor fontDescriptorWithFontAttributes:@{UIFontDescriptorFamilyAttribute: @"Arial"}]; UIFontDescriptor* boldFontDescriptor1 = [descriptor1 fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; UIFont* font1 = [UIFont fontWithDescriptor:boldFontDescriptor1 size:16.0]; [self.lblArialB setFont