删除iOS UIBarButtonItem的标题文本 [英] Removing the title text of an iOS UIBarButtonItem
问题描述
我想要做的是从 UIBarButtonItem
的后退按钮中删除文本,只在导航栏上留下蓝色V形符号。请记住,我正在为iOS 7开发。我尝试了几种方法,包括但不限于:
What I wanted to do is to remove the text from the 'Back' button of a UIBarButtonItem
, leaving only the blue chevron on the navigation bar. Keep in mind that I'm developing for iOS 7. I've tried several methods, including, but not limited to:
这是我没有的图像方法喜欢(图像看起来不合适):</ p>
This is the image method which I did not like (the image looked out of place):
UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iOS7BackButton"] style:UIBarButtonItemStylePlain target:self action:@selector(goToPrevious:)];
self.navigationItem.leftBarButtonItem = barBtnItem;
我试过的另一种方法就是这个,它根本不起作用(没有显示任何内容):
Another method I tried was this, which simply did not work (nothing was displayed):
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc]init];
barBtn.title=@"";
self.navigationItem.leftBarButtonItem=barBtn;
我想要实现的是iOS 7音乐应用程序中的后退按钮,仅限于有一个单一的雪佛龙。
What I wanted to achieve is something like the back buttons found in the iOS 7 Music app, which only featured a single chevron.
谢谢。
推荐答案
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60)
forBarMetrics:UIBarMetricsDefault];
然后你可以删除后退按钮项目标题。
Then you can remove the back button item title.
如果您使用Storyboard,则可以使用空格设置导航属性检查器后退按钮。
If you use Storyboard, you can set navigation attributes inspector Back Button with space.
这篇关于删除iOS UIBarButtonItem的标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!