简体   繁体   中英

Custom Font not working in iOS 8

i am working on one Project on my Project i want to add custom font like as Calibri Bold.ttf and Calibri.ttf for this i added this both file in my application and in my info.plist file i added Fonts Provided by Aplication then it is shown in my Font but when i want to set in to my String it shows me error like as

-(NSMutableAttributedString *)getAttributedString:(NSString*)lostr
{
NSMutableAttributedString *loMutAttStr = [[NSMutableAttributedString alloc]initWithString:lostr];
NSArray *loArr = [lostr componentsSeparatedByString:@"("];
NSRange loRange1 = NSMakeRange(0,[[loArr objectAtIndex:0] length]-1);
NSRange loRange2 = NSMakeRange([lostr length]-[[loArr objectAtIndex:[loArr count]-1] length]-1,[[loArr objectAtIndex:[loArr count]-1] length]+1);

UIColor *loColor = [UIColor blackColor];
UIColor *loColr1= [UIColor  grayColor];

[loMutAttStr addAttribute:NSForegroundColorAttributeName value:loColor range:loRange1];
[loMutAttStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Calibri Bold" size:30] range:loRange1];
if([loArr count] > 1)
{
    [loMutAttStr addAttribute:NSForegroundColorAttributeName value:loColr1 range:loRange2];
    [loMutAttStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Calibri" size:30] range:loRange2];
}
return loMutAttStr;
}

then it shows me error NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString addAttribute:value:range:: nil value' in line

[loMutAttStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Calibri Bold" size:30] range:loRange1];

Please give me solution for this here my string is not nil and when i set font HelveticaNeue instead of Calibri then it is working fine.

Look here for adding custom font http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

Print fonts supported by app

for (NSString* family in [UIFont familyNames])
{
    NSLog(@"%@", family);

    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM