2

如何在 ios 7 的笔记应用程序中重新创建应用于 backbarbuttonitem 的凸版效果?我尝试了以下方法:

NSShadow *textShadow = [[NSShadow alloc] init];
textShadow.shadowOffset = CGSizeMake(0.0, -1.0);
textShadow.shadowColor = [UIColor blackColor];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:@"Back" attributes:@{NSForegroundColorAttributeName : [UIColor orangeColor], NSShadowAttributeName : textShadow}];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:attributedTitle style:UIBarButtonItemStylePlain target:nil action:nil];

但它说我不能使用 NSAttributedString 代替 NSString。

4

1 回答 1

2

对于 iOS 5 及更高版本,您可以使用该UIAppearance功能更改多个 UI 组件(如 UITabBar、UIBarButton 等)的文本颜色、字体、色调颜色等。

对于 UIBarButtonItem,请检查以下两个选项。


选项 1:对于任何 UIBarButtonItem:

NSDictionary *aButtonAttribute = [NSDictionary dictionaryWithObjectsAndKeys:
                                [UIColor darkGrayColor], UITextAttributeTextColor,
                                [UIColor whiteColor], UITextAttributeTextShadowColor,
                                [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:aButtonAttribute forState:UIControlStateNormal];

选项 2:仅适用于 UINavigationBar 的 UIBarButtonItem:

NSDictionary *aButtonAttribute = [NSDictionary dictionaryWithObjectsAndKeys:
                            [UIColor darkGrayColor], UITextAttributeTextColor,
                            [UIColor whiteColor], UITextAttributeTextShadowColor,
                            [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil];

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:aButtonAttribute forState: UIControlStateNormal];

注意:您可以在 AppDelegate 的 .m 文件中添加这些行(两个选项之一)。

于 2013-10-06T12:03:47.263 回答