单击UINavigationBar按钮时的光泽效果

时间:2012-11-17 13:25:18

标签: objective-c ios uibutton uinavigationbar

当我点击位于UIButton顶部的UINavigationBar时,我有这种光泽效果:

glossy

如何将此效果添加到位于UINavigatonBar但不作为左或右按钮项目的另一个按钮?像这样:

UIButton * emptyButton = [UIButton buttonWithType:UIButtonTypeCustom];
[emptyButton setFrame:CGRectMake(119, 5, 82, 35)];
[emptyButton addTarget:self action:@selector(centerNavigationBarTitleClicked:) forControlEvents:UIControlEventTouchUpInside];
[emptyButton setBackgroundColor:[UIColor clearColor]];

[self.navigationController.navigationBar addSubview:emptyButton];

谢谢!

1 个答案:

答案 0 :(得分:4)

您只需将showsTouchWhenHighlighted属性设置为YES即可获得发光效果,即

emptyButton.showsTouchWhenHighlighted = YES;