6

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.

Metodij Zdravkin
  • 914
  • 1
  • 14
  • 23
  • 2
    I have the same issue too with the Baskerville font. In fact, I am doing iOS 7 tutorial by Ray Wenderlich. As you said, this is a iOS 8 specific problem. – Ken Hui Sep 25 '14 at 09:58

2 Answers2

6

FWIW, this is the workaround I came up with, using UIFontDescriptor's attributes dictionary initializer instead of the seemingly buggy fontDescriptorWithSymbolicTraits:

NSString *fontFamily = @"Arial";
BOOL isBold = YES;
BOOL isItalic = YES;
CGFloat fontSize = 20.0;
UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:
                  @{
                    @"NSFontFamilyAttribute" : fontFamily,
                    @"NSFontFaceAttribute" : (isBold && isItalic ? @"Bold Italic" : (isBold ? @"Bold" : (isItalic ? @"Italic" : @"Regular")))
                    }];
UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:fontSize];
neural5torm
  • 773
  • 1
  • 9
  • 21
  • @neural5torm: How'd use that in Swift? Checked on the [Apple documentation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIFontDescriptor_Class/#//apple_ref/occ/clm/UIFontDescriptor/fontDescriptorWithFontAttributes:) but seems that isn't documented :( My implementation looks like [this](https://gist.github.com/alexszilagyi/ca0a4ce3dd1b4ddcbba3), do you mind if you take a look? – el.severo Mar 18 '16 at 23:50
  • Instead of fontFamily, How can I use my textfield system font and size? I want only bold – Mihir Oza Jul 16 '16 at 05:28
0

For me, the fontDescriptorWithFontAttributes is working as before but the fontDescriptorWithSymbolicTraits fails miserably. I solved it by going back to using [UIFont fontWithName: size:]

[self.titleLabel setFont:[UIFont fontWithName:@"PTSans-Bold" size:47.67]];
user3802077
  • 849
  • 9
  • 22