如何以编程方式删除 UIBarButtonItem 发光? [英] How do I remove UIBarButtonItem glow programmatically?

查看:33
本文介绍了如何以编程方式删除 UIBarButtonItem 发光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,UIBarButtonItem 没有showsTouchWhenHighlighted,我无法从工具栏编辑我的按钮...

Unfortunately there is no showsTouchWhenHighlighted for UIBarButtonItem and I can't edit my button from the toolbar...

推荐答案

负责此操作的属性可在 UIButton 类中访问:

The property responsible for this is accessible in the UIButton class:

myButton.showsTouchWhenHighlighted = NO;

您可以通过将 UIButton 分配给条形按钮项的 customView 属性并配置该按钮,在 UIBarButtonItem 中(以编程方式)访问它.您也可以在 Interface Builder 中执行此操作:将 UIButton 拖到 UIToolbar 上,它会自动为您将其嵌入 UIBarButtonItem - 然后在按钮设置下查找Shows Touch On Highlight"复选框.

You can access this (programmatically) in a UIBarButtonItem by assigning a UIButton to the bar button item's customView property, and configuring the button. You can do this in Interface Builder too: drag a UIButton onto a UIToolbar, and it will automatically embed it in a UIBarButtonItem for you - then look for the "Shows Touch On Highlight" checkbox under the button's settings.

顺便说一句,我不知道您是如何自定义按钮的,因此请随意忽略这一点,但如果您的按钮看起来和行为类似于标准工具栏项,那么用户就会期待发光效果.

Incidentally, I don't know how you're customising your buttons so feel free to ignore this, but if your button looks and behaves like a standard toolbar item then users will expect the glow effect.

来自这里的答案

编辑:

试试这个:

UIImage* buttonImage = [UIImage imageNamed: @"header.navigation.back.png"];     
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame =  CGRectMake(0.0, 0.0, buttonImage.size.width/2, 32);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(backToPriorView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];

这篇关于如何以编程方式删除 UIBarButtonItem 发光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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