Xcode 6 Size Classs中的自定义字体大小无法与自定义字体一起正常使用 [英] Custom Font Sizing in Xcode 6 Size Classes not working properly with Custom Fonts

查看:93
本文介绍了Xcode 6 Size Classs中的自定义字体大小无法与自定义字体一起正常使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 6 具有一项新功能,可以将UILabelUITextFieldUIButton中的字体字体大小设置为根据当前设备配置的大小类别自动设置,就在情节提要中.例如,您可以设置UILabel以在任何宽度,紧凑高度"配置(例如在横向iPhone上)上使用字体大小12,在常规宽度,常规高度"配置(例如在上使用字体大小18). > iPad ).可在此处获得更多信息:

Xcode 6 has a new feature where fonts and font sizes in UILabel, UITextField, and UIButton can be set automatically based on the size class of the current device configuration, right in the storyboard. For example, you can set a UILabel to use font size 12 on "any width, compact height" (such as on iPhones in landscape) configurations and size 18 on "regular width, regular height" configurations (such as on iPads). More information is available here:

developer.apple.com/size_class

从理论上讲,这是一个很棒的功能,因为它可能不需要基于设备配置以编程方式在UI功能上设置不同的字体.现在,我有一些条件代码可以根据设备类型设置字体,但是很明显,这意味着我必须在整个应用中的所有位置以编程方式设置字体.因此,我最初对该功能感到非常兴奋,但是我发现它对我的实际使用存在严重问题(可能是一个错误).请注意,我是根据 SDK 8 构建的,并将最低部署目标设置为 iOS 8 ,因此这与与旧版本的iOS的兼容性无关.

This is a great feature in theory because it could make it unnecessary to programmatically set different fonts on UI features based on the device configuration. Right now, I have some conditional code that sets the fonts based on the device type, but obviously, that means I have to set the fonts programmatically everywhere throughout the app. So I was initially really excited about this feature, but I found that it has a severe problem of actual usage for me (perhaps a bug). Note that I am building against SDK 8 and setting a minimum deployment target of iOS 8, so this has nothing to do with compatibility with old versions of iOS.

问题是这样的: 如果我为不同的尺寸类别设置了不同的字体大小,并使用了由 iOS 提供的系统"字体,则一切都会按预期运行,并且字体大小会根据尺寸类别而变化.如果我使用应用程序提供的自定义字体(是的,我已经在我的应用程序包中正确设置了它,因为它可以以编程方式工作),然后在 XCode中将自定义字体设置为 label 6个分镜脚本,它也可以按预期工作.但是,当我尝试对不同大小的类使用不同大小的自定义字体时,在情节提要中,它突然不起作用.配置上的唯一区别是我选择的字体(自定义字体与系统字体).而是,所有字体以默认大小的形式显示为默认系统字体,作为设备和模拟器,而不管大小类别(和我通过调试器验证,它正在将系统字体替换为情节提要中指定的实际字体).因此,基本上,自定义字体的大小类功能似乎已损坏.另外,有趣的是,自定义字体实际上在视图控制器的XCode 6预览"窗格中正确显示和调整大小:仅当在实际的iOS系统上运行时,它才会停止工作(这使我认为我在正确配置它)

The problem is this: If I set different font sizes for different size classes and use the "System" font provided by iOS, everything works as expected, and the font sizes change based on the size class. If I use a custom font supplied by my application (yes, I have it set up correctly in my application bundle, as it works programmatically) and set the custom font to a label in an XCode 6 storyboard, that also works as expected. But when I try to use different sizes of the custom font for different size classes, in the storyboard, it suddenly doesn't work. The only difference in configuration is the font I've chosen (a custom one vs. the System font). Instead, all of the fonts show up on the device and simulator as the default system font at the default size, regardless of size class (and I verified via the debugger that it is substituting the system font for the actual one specified in the storyboard). So basically, the size class feature appears to be broken for custom fonts. Also, interestingly, the custom fonts actually display and adjust size properly in the XCode 6 "Preview" pane for the view controller: it stops working only when running on the actual iOS system (which makes me think that I'm configuring it correctly).

我尝试了多种不同的自定义字体,它似乎不适用于其中任何一种,但是如果我改用系统",它总是可以使用的.

I tried multiple different custom fonts, and it doesn't seem to work for any of them, but it always works if I use "System" instead.

无论如何,还有其他人在 Xcode 6 中看到此问题吗?

Anyway, has anyone else seen this problem in Xcode 6?

关于这是否是iOS 8,Xcode或其他错误的任何想法

Any ideas on whether this is a bug in iOS 8, Xcode, or something

我做错了吗?

正如我所说,我发现的唯一解决方法是继续以编程方式设置字体,就像我在大约三个iOS版本中一样,因为它确实可以工作.

The only workaround I've found, as I said, is to continue to programmatically set the fonts like I have been for about three versions of iOS because that does work.

但是,如果我可以使用自定义字体,我希望能够使用此功能.我们的设计不接受使用系统字体.

But I'd love to be able to use this feature if I could get it to work with custom fonts. Using the System font is not acceptable for our design.

其他信息: 从Xcode 8.0开始,该错误已修复.

ADDITIONAL INFO: As of Xcode 8.0, the bug is fixed.

推荐答案

快速修复:

1)将字体设置为大小类的系统

1) Set fonts as System for size classes

2)子类化UILabel并覆盖"layoutSubviews"方法,例如:

2) Subclass UILabel and override "layoutSubviews" method like:

- (void)layoutSubviews
{
  [super layoutSubviews];

   // Implement font logic depending on screen size
    if ([self.font.fontName rangeOfString:@"bold" options:NSCaseInsensitiveSearch].location == NSNotFound) {
        NSLog(@"font is not bold");
        self.font = [UIFont fontWithName:@"Custom regular Font" size:self.font.pointSize];
    } else {
        NSLog(@"font is bold");
        self.font = [UIFont fontWithName:@"Custom bold Font" size:self.font.pointSize];
    }

}

顺便说一句,这是一种非常方便的图标字体技术

By the way, it is a very convenient technique for iconic fonts

这篇关于Xcode 6 Size Classs中的自定义字体大小无法与自定义字体一起正常使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆