iPhone: How to remove glow (light) from UIBarButtonItem when pressed?

醉酒当歌 提交于 2020-01-23 18:48:06

问题


I'm trying to remove the glow from a UIBarButton item so that my text appears to be a label instead of a button. I've seen various posts talking about how to do this through interface builder or by setting a boolean variable "showsTouchWhenHighlighted", but neither of these options are available to me it appears. I've tried setting the showsTouchWhenHighlighted in the .m viewDidLoad where I change the font and font-size but the UIBarButtonItem doesn't appear to have that property. I also only have the options in the following image to change in InterfaceBuilder.


回答1:


There is a way to do this (a bit of a hack but it works). Just drag a UIButton into your toolbar (instead of a UIBarButtonItem). Then a UIBarButtonItem will be automatically be created for you as a superview for your UIButton. Then you just set it like this:

UIBarButtonItem

  • Style: Plain
  • Title: (empty)

UIButton

  • Type: Custom
  • Title: (your actual label title here)
  • Text Color: White
  • Shows Touch On Highlight: (Unchecked)

Here is a screenshot to use as reference:

Note: Just remember that from now on any updates on the text must be made on the UIButton




回答2:


try this:

`

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(140 , 0, 50, 250)];
    [label setBackgroundColor:[UIColor clearColor]];
    label.text = @"TEXT";
    UIView *view = (UIView *) label;
    [self.barItem setCustomView:view];

`

note: self.barItem is a UIBarButtonItem added from the object library and placed between two flexible spaces.

another way is to remove the [self.barItem setCustom:view] line and change the parameters of the label (width) so that it fills the entire toolbar and set the alignment to middle and the font by yourself in code,



来源:https://stackoverflow.com/questions/11384879/iphone-how-to-remove-glow-light-from-uibarbuttonitem-when-pressed

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