iPhone: How to remove glow (light) from UIBarButto

2019-06-03 23:42发布

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.

enter image description here

2条回答
Rolldiameter
2楼-- · 2019-06-03 23:56

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: enter image description here

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

查看更多
甜甜的少女心
3楼-- · 2019-06-04 00:13

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,

查看更多
登录 后发表回答