UIButton 中的图像比原始图像更暗 [英] Image in UIButton is darker tharn original

查看:30
本文介绍了UIButton 中的图像比原始图像更暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在背景中已有 UIImageView 的单元格中添加 UIButton.

I'm trying to add a UIButton in a cell which already has a UIImageView in the background.

我把这段代码放在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 中的图像看起来更暗

It works but the image in the UIButton is seems darker

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

I tried these but it didn't changed anything

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

有没有人对此有解释,以及解决方案.

Does anyone have an explanation for this, and a solution as well.

推荐答案

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

I had the same problem once and I solved it by setting the button's image for the UIControlStateHighlighted

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

希望对你有用

这篇关于UIButton 中的图像比原始图像更暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆