setTitleTextAttributes无法正常工作

时间:2015-09-30 20:05:45

标签: ios objective-c iphone uifont

您好,我一直面临这个奇怪的错误,该应用程序仅适用于iPhone 6。

所以在我的一个方法中我有

- (void)dummy {
   UIFont *titleFont = [HTFont thinFontOfSize:20];
   [[UINavigationBar appearance] setTitleTextAttributes:@{ 
   NSFontAttributeName:titleFont }];
}

如果我发表评论,该应用适用于iPhone 4s

我认为HTFont文件有问题,但我似乎无法弄明白。

HTFont.m

#define IS_IPAD   (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define SCREEN_WIDTH  CGRectGetWidth([[UIScreen mainScreen] bounds])
#define SCREEN_HEIGHT CGRectGetHeight([[UIScreen mainScreen] bounds])

#define IS_IPHONE4  (IS_IPHONE && MAX(SCREEN_WIDTH, SCREEN_HEIGHT) < 568.0)
#define IS_IPHONE5  (IS_IPHONE && MAX(SCREEN_WIDTH, SCREEN_HEIGHT) == 568.0)
#define IS_IPHONE6  (IS_IPHONE && MAX(SCREEN_WIDTH, SCREEN_HEIGHT) == 667.0)
#define IS_IPHONE6P (IS_IPHONE && MAX(SCREEN_WIDTH, SCREEN_HEIGHT) == 736.0)

static NSString * const kFontName = @"SourceSansPro-Regular";
static NSString * const kThinName = @"SourceSansPro-Light";

@implementation HTFont

+ (UIFont *)fontOfSize:(CGFloat)size {

    return [UIFont fontWithName:kFontName size:[HTFont     adjustedFontSizeForScreen:size]];
}

+ (UIFont *)thinFontOfSize:(CGFloat)size {

    return [UIFont fontWithName:kThinName size:[HTFont     adjustedFontSizeForScreen:size]];
}

+ (CGFloat)adjustedFontSizeForScreen:(CGFloat)size {

    if (IS_IPHONE5) {

       return size;

    } else if (IS_IPHONE6) {

        return size * 1.1;

    } else if (IS_IPHONE6P) {

       return size * 1.2;

    } else {

        return size * 0.9;
    }
}

可能导致错误的原因是什么?

*** Terminating app due to uncaught exception    
'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary    
initWithObjects:forKeys:count:]: attempt to insert nil object from   
objects[1]'
*** First throw call stack:

0 个答案:

没有答案