scaledValueForValue: called on a font that doesn't have a text style set

前端 未结 8 2020
暗喜
暗喜 2020-12-24 01:46

I am currently using the Xcode 6 pre release (not beta) and the simulator on OS X 10.10 Yosemite beta 7. I am trying to build a project developed in xcode 6, but the app cra

相关标签:
8条回答
  • 2020-12-24 01:56

    This problem has been fixed in iOS 8.1.

    Instead of spending time building a custom header/footer view, I just not apply the custom font to devices running iOS 8.0. Most people will probably have updated to iOS 8.1 anyway.

    I use the following code for this:

    NSOperatingSystemVersion iOS_8_1 = (NSOperatingSystemVersion){8, 1, 0};
    
    if (![[NSProcessInfo processInfo] respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)]
        || [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:iOS_8_1]) {
        header.textLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:header.textLabel.font.pointSize];
    }
    

    The first statement is true if the device is running an iOS version lower than 8 (since isOperatingSystemAtLeastVersion: was introduced in iOS 8.0). The second statement is true if the device if running iOS 8.1 or later. With both statements we thus only exclude devices running iOS 8.0.

    0 讨论(0)
  • 2020-12-24 01:57

    Like everyone here, applying the fix in other answers caused the font setting to be ignored. What I ended up doing was having my own UITableViewHeaderFooterView (Where it seems the cause for the crash is coming from) subclasses that had a label that I added myself. I then used this label instead of the textLabel property inherited from UITableViewHeaderFooterView, set up the auto layout constraints, set the font, and all was right once again (though not what I would consider ideal). I'll add again that this seems to be iOS 8 unique.

    0 讨论(0)
  • Take a look at: http://openradar.io/17623734

    Unfortunately at this early stages of xCode 6 I can only offer a workaround for the crash.

    Replace this line:

    [header.textLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17]];
    

    for this:

    header.textLabel.font = [UIFont fontWithDescriptor:[UIFontDescriptor fontDescriptorWithFontAttributes:@{@"NSCTFontUIUsageAttribute" : UIFontTextStyleBody,
                                                                                                            @"NSFontNameAttribute" : @"HelveticaNeue-Italic"}] size:17.0];
    
    0 讨论(0)
  • 2020-12-24 02:01

    Finally found workaround. It is simple, you just need to construct font in other direction :)

    // 1. Grab your custom font
    CGFloat size = 17.0f;
    UIFont *font = [UIFont fontWithName:@"Brandon Grotesque" size:size];
    
    // 2. Get descriptor for your font and create new descriptor with
    UIFontDescriptorTextStyleAttribute and UIFontDescriptorSizeAttribute attributes from it.
    
    UIFontDescriptor *des = [[font fontDescriptor] fontDescriptorByAddingAttributes:@{
       UIFontDescriptorTextStyleAttribute: UIFontTextStyleBody, // You can tune this style based on usage
       UIFontDescriptorSizeAttribute: @(size)
    }];
    
    // 3. Get your font
    UIFont *finalFont = [UIFont fontWithDescriptor:des size:0.0]
    
    0 讨论(0)
  • 2020-12-24 02:02

    This only happens for me when using either a UITableView or UITableViewController where initWithStyle: method call is set to UITableViewStyleGrouped. Changing the style to UITableViewStylePlain resolved the issues.

    0 讨论(0)
  • 2020-12-24 02:02

    Same problem here: set a custom font for UITableViewHeaderFooterView in my app init, get this crash when showing a grouped UITableView.

    What works for me is to delay customisation until the view controller is being created, i.e. do whatever you would have done at app init in the view controller's init. Irritating, but works for me.

    - (id) init
    {
      ...
    
      if (self = [super init])
      {
        // customise table view headers
        UILabel *headerLabel =
          [UILabel appearanceWhenContainedIn: [UITableViewHeaderFooterView class], nil];
    
        headerLabel.font =
          [UIFont fontWithName: @"AvenirNext-Medium" size: 15];
    
        ...
      }
    }
    
    0 讨论(0)
提交回复
热议问题