Backbarbuttonitem凸版印刷效果 [英] Backbarbuttonitem letterpress effect

查看:139
本文介绍了Backbarbuttonitem凸版印刷效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I recreate the letterpress-like effect applied to the backbarbuttonitem in the notes app in ios 7? I tried the following:

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。

But it says I can't use NSAttributedString in place of an NSString.

推荐答案

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

For iOS 5 and above, you can use the UIAppearance functionality to change the Text Color, Font, Tint Color etc of multiple UI Components like UITabBar, UIBarButton, etc.

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

for UIBarButtonItem, check the below two options.

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:




Option 2: For UIBarButtonItem of a UINavigationBar ONLY:

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个选项中的任何一个)..


NOTE: You can add these lines (either of the 2 options) in the .m file of AppDelegate..

这篇关于Backbarbuttonitem凸版印刷效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆