How do I remove UIBarButtonItem glow programmatically?

前提是你 提交于 2019-12-24 13:34:13

问题


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


回答1:


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

myButton.showsTouchWhenHighlighted = NO;

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.

Answer from here

EDIT:

Try this then:

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];


来源:https://stackoverflow.com/questions/13622941/how-do-i-remove-uibarbuttonitem-glow-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!