objective-c - UIButton 中的图像比原始图像更暗

标签 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];

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

最佳答案

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

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

希望它对你有用

关于objective-c - UIButton 中的图像比原始图像更暗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10474536/

相关文章:

ios - UIImageView+AF联网及保存图片

ios - 如果我们不在 init 方法中检查 "if (self)"会发生什么?

swift - 在媒体繁重的 swift 应用程序中管理内存的正确方法是什么?释放它?

ios - 为什么发送addTarget方法具有:才能工作

iphone - (iPhone SDK) 如何通过标签id修改UIButton?

ios - 尝试加粗 UIButton 的 titleLabel 以响应在 iOS 中调用的委托(delegate)方法

iphone - 查找 UIImage 文件类型

objective-c - 设计一个接口(interface)而不是 Objective-C 中的实现

ios - 使用 CAKeyframeAnimation 沿 UIBezierPath 移动 UIImageView 不会执行任何操作

ios - 如何在自定义表格 View 单元格中保留图像的选定状态?