录制UIBar按钮项目时的白色

时间:2013-06-05 01:31:37

标签: ios objective-c

我使用下面的代码创建了一个自定义栏按钮项。

UIImage* image3 = [UIImage imageNamed:@"iphone-btn-next@2x.png"];
CGRect frameimg = CGRectMake(0, 0,57,44);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton setBackgroundImage:image3 forState:UIControlStateHighlighted];
[someButton addTarget:self action:@selector(flipView)
     forControlEvents:UIControlEventTouchUpInside];
[someButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.rightBarButtonItem=mailbutton;

并且它工作正常,但问题是当我点击按钮时,我可以看到按钮中心的白色(见截图)。有人可以告诉我摆脱它的方法吗?

enter image description here

2 个答案:

答案 0 :(得分:4)

删除这行代码:

[someButton setShowsTouchWhenHighlighted:YES];

根据文件

showsTouchWhenHighlighted => A Boolean value that determines whether tapping the button causes it to glow.

答案 1 :(得分:2)

这应该是写答案

删除行

[someButton setShowsTouchWhenHighlighted:YES];

试试这个而不是

UIImage* image3 = [UIImage imageNamed:@"iphone-btn-next@2x.png"];
CGRect frameimg = CGRectMake(0, 0,57,44);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton setBackgroundImage:image3 forState:UIControlStateHighlighted];
[someButton addTarget:self action:@selector(flipView)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.rightBarButtonItem=mailbutton;