我如何在ios 7的笔记应用程序中重新创建应用于backbarbuttonitem的类似letterpress的效果?我尝试了以下几种方法:
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。
发布于 2013-10-06 20:03:47
对于iOS 5和更高版本,您可以使用UIAppearance功能来更改UITabBar、UIBarButton等多个UI组件的文本颜色、字体、染色颜色等。
对于UIBarButtonItem,请选中以下两个选项。
Option1:对于任何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文件中添加这些行(这两个选项中的任意一个)。
https://stackoverflow.com/questions/19208327
复制相似问题