Backbarbuttonitem凸版印刷效果

时间:2013-10-06 11:22:40

标签: iphone ipad ios7 letterpress

如何在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。

1 个答案:

答案 0 :(得分: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文件中添加这些行(2个选项中的任意一个)。

相关问题