UIButton中的图像是原始的较暗的图像

时间:2012-05-06 21:40:25

标签: objective-c uiimageview uibutton

我正在尝试在后台已经有 UIImageView 的单元格中添加 UIButton

我将此代码放在configureCell

UIButton *mail = [[UIButton alloc] initWithFrame:CGRectMake(10, 270, 40, 40)];
[mail setImage:[UIImage imageNamed:@"mail.png"] forState:UIControlStateNormal];
mail.backgroundColor = [UIColor whiteColor];
[mail addTarget:self action:@selector(sendMail) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:mail];

它可以工作,但 UIButton 中的图像看起来更暗

Original Darker one

我尝试了这些,但它没有改变任何东西

mail.alpha = 1;
[cell.contentView bringSubviewToFront:mail];

有没有人对此有解释,也有解决方案。

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,我通过设置UIControlStateHighlighted按钮的图像来解决它

[mail setImage:[UIImage imageNamed:@"mail.png"] forState:UIControlStateHighlighted];

希望它适合你

答案 1 :(得分:0)

试试这个

UIButton *mail=[UIButton buttonWithType:UIButtonTypeCustom];
mail.frame= CGRectMake(10, 270, 40, 40);
[mail setImage:[UIImage imageNamed:@"mail.png"] forState:UIControlStateNormal];
mail.backgroundColor = [UIColor clearColor];
[mail addTarget:self action:@selector(sendMail) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:mail];