Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font Descriptor returns nil in iOS 8

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.

like image 548
Metodij Zdravkin Avatar asked Sep 22 '14 14:09

Metodij Zdravkin


1 Answers

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];
like image 146
neural5torm Avatar answered Oct 15 '22 06:10

neural5torm