你可能和我一样,过于热心地削减和替换了UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset的编译器警告。因此,你有着类似以下代码的代码:
NSDictionary *titleAttributes = @{UITextAttributeTextColor: [UIColor whiteColor],
UITextAttributeTextShadowColor: [UIColor blackColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
UITextAttributeFont: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];
然后用NSShadowAttributeName替换了它们两个,最终得到了如下的代码:
NSDictionary *titleAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
NSShadowAttributeName: [UIColor blackColor],
NSShadowAttributeName: [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
NSFontAttributeName: [UIFont titleBolder]}
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes]
您需要做的是拥有一个NSShadowAttributeName属性,并创建一个包含阴影颜色和阴影偏移量的NSShadow实例。
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blackColor];
shadow.shadowOffset = CGSizeMake(1, 0);
NSDictionary *titleAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
NSShadowAttributeName: shadow,
NSFontAttributeName: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];