Image in UIButton is darker tharn original

别等时光非礼了梦想. 提交于 2019-12-11 02:03:13

问题


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

I put this code in 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];

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.


回答1:


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

Hope it works for you




回答2:


Try this

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


来源:https://stackoverflow.com/questions/10474536/image-in-uibutton-is-darker-tharn-original

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!