Tag: uifontdescriptor

在旧金山使用fontWithSize API

通过调整SF Display和SF Text之间的dynamic跟踪和dynamic切换,iOS 9中新的旧金山字体将根据其使用的尺寸进行优化。 在WWDC会议中注意到,#804开发者不应该使用fontWithName尝试初始化UIFont来使用fontWithName ,例如: UIFont *originalFont = [UIFont systemFontOfSize:11]; UIFont *newFont = [UIFont fontWithName:originalFont.fontName size:44]; 这是因为在使用fontWithName API时,系统无法为新大小优化字体。 相反,build议从原始字体中获取UIFontDescriptor ,并按照新的大小创build一个新的字体,如下所示: UIFont *originalFont = [UIFont systemFontOfSize:11]; UIFont *newFont = [UIFont fontWithDescriptor:originalFont.fontDescriptor size:44]; 但是,他们没有提到以下是否允许优化: UIFont *originalFont = [UIFont systemFontOfSize:11]; UIFont *newFont = [originalFont fontWithSize:44]; 我的问题是, fontWithSize API的行为是否像fontWithName API或fontWithDescriptor API – 是否导致新的大小的优化字体?

在iOS上显示按比例分配的数字(而不是等宽/表格)

我在iOS中渲染数字(目标是7或更高),方法是将它们存储在NSAttributedString中,并使用“drawAtPoint:”进行渲染。 我正在使用Helvetica Neue。 我已经注意到, 像这样绘制的数字不是成比例的 – 这些字形都具有相同的宽度。 即使是一个瘦的“1”也占据了与“0”相同的空间。 一个testing证实了这一点: for(NSInteger i=0; i<10; ++i) { NSString *iString = [NSString stringWithFormat: @"%d", i]; const CGSize iSize = [iString sizeWithAttributes: [self attributes]]; NSLog(@"Size of %d is %f", i, iSize.width); } 与其他地方一起: -(NSDictionary *) attributes { static NSDictionary * attributes; if(!attributes) { attributes = @{ NSFontAttributeName: [UIFont systemFontOfSize:11], NSForegroundColorAttributeName: […]

字体描述符在iOS 8中返回零

下面的代码可以在iOS 7中正常工作,但是不会在iOS 8中返回粗体或斜体字体。对于Helvetica Neue来说没问题,但是对Arial字体不起作用。 UIFontDescriptor *descriptor1 = [UIFontDescriptor fontDescriptorWithFontAttributes:@{UIFontDescriptorFamilyAttribute: @"Arial"}]; UIFontDescriptor* boldFontDescriptor1 = [descriptor1 fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; UIFont* font1 = [UIFont fontWithDescriptor:boldFontDescriptor1 size:16.0]; [self.lblArialB setFont:font1]; 在设备和模拟器上testing,仍然是一样的错误。