如何取消UIBarbuttonItem setTitle闪亮效果

How to cancel UIBarbuttonItem setTitle shining effect

如图所示,我使用UIBarbuttonItem作为rightBarButtonItem,我想做的只是在我select一张图片或deselect一张图片时改变rightBarButton的标题,所以我使用了这样的代码:

[self.rightBarButton setTitle:[NSString stringWithFormat:@"完成(%@/%@)",@(_selectedAssets.count),@(self.maxPicturesNum)]];

但是当barbutton的文本改变时会显示shin,我尝试使用UIButton而不是UIBarButtonItem,shin效果确实消失了,但是UIButton会很接近右边边界,你能帮我吗?

您可以创建 UIButton 并将其分配给您的 rightBarButton

UIButton *rightButton = [[UIButton alloc] initWithFrame:someFrame];
[rightButton setBackgroundImage:someImage forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
rightButton.titleLabel.text = [NSString stringWithFormat:@"完成(%@/%@)",@(_selectedAssets.count),@(self.maxPicturesNum)];
rightButton.titleLabel.font = someFont;
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.rightBarButton = rightBarButtonItem;

更新标签时使用 rightButton.titleLabel.text

调整标签使用这个:

- (void)setTitlePositionAdjustment:(UIOffset)adjustment
                 forBarMetrics:(UIBarMetrics)barMetrics

最后,我喜欢这样:

- (void)loadRightButtonItem{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(30, 0, 120, 40);
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
[button setTitle:@"完成(0/9)" forState:UIControlStateNormal];
button.tintColor = [UIColor whiteColor];
[button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//    [button setTitleColor:[self.buttonFolder titleColorForState:UIControlStateHighlighted] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(onFinishClicked:) forControlEvents:UIControlEventTouchUpInside];

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 135, 40)];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:view];

[view addSubview:button];
self.navigationItem.rightBarButtonItem = item;
_rightBarButton = button;
}

它取消了胫骨效果。

感谢@RoHaN,你的想法对我很有启发。