【问题标题】:Image in UIButton is darker tharn originalUIButton 中的图像比原始图像更暗
【发布时间】:2012-05-08 01:52:09
【问题描述】:

我正在尝试在后台已经有 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 中的图像看起来更暗

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

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

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

【问题讨论】:

    标签: objective-c uiimageview uibutton


    【解决方案1】:

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

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

    希望对你有用

    【讨论】:

    • 好的,我不太明白为什么,但它确实有效,谢谢。
    【解决方案2】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 1970-01-01
      • 2018-05-24
      • 2017-07-11
      • 1970-01-01
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多