I am trying to add custom font in my application GothamPro-NarrowMedium
I added the .otf
file in my project and in info.plist
I added Fonts provided by the application and added to target membership. Now when I assign the font through Interface it works perfectly when I try to add it in NSMutableAttributedString
I get the below exception
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]' * First throw call stack: (0x181ad6fe0 0x180538538 0x1819bd9b4 0x1819bd824 0x100075dac 0x100073fa8 0x187c07ec0 0x187c07a9c 0x187f975f0 0x187f5bce0 0x187f58130 0x187e94950 0x187e869ec 0x187bfa648 0x181a849a8 0x181a82630 0x181a82a7c 0x1819b2da4 0x18341c074 0x187c6d058 0x10011ff44 0x1809c159c) libc++abi.dylib: terminating with uncaught exception of type NSException
My code is
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = _lbl_mylabel.textAlignment;
NSDictionary *attribs = @{
NSForegroundColorAttributeName: self.lbl_ticketdetail.textColor,
NSFontAttributeName: self.lbl_ticketdetail.font
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text
attributes:attribs];
paragraphStyle.lineSpacing = 3;
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"GothamPro-NarrowMedium" size:20.0],NSParagraphStyleAttributeName:paragraphStyle}
range:cmp];
NSRange plce = [text rangeOfString:place];
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"GothamPro-NarrowMedium" size:16.0],NSParagraphStyleAttributeName:paragraphStyle}
range:plce];
NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
paragraphStyle1.lineSpacing = 1;
NSRange tkt_num_range = [text rangeOfString:STR_tkt_num_club];
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"GothamMedium" size:13.0],NSParagraphStyleAttributeName:paragraphStyle1} range:tkt_num_range];
self.mylabel.attributedText = attributedText;