首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Backbarbuttonitem项目凸版效果

Backbarbuttonitem项目凸版效果
EN

Stack Overflow用户
提问于 2013-10-06 19:22:40
回答 1查看 528关注 0票数 2

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

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

发布于 2013-10-06 20:03:47

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

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

Option1:对于任何UIBarButtonItem:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19208327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档