您可能做了我所做的,并且过分热心地剪切和替换了 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];