【问题标题】:IOS 7 button image colorIOS 7按钮图像颜色
【发布时间】:2014-03-27 10:30:42
【问题描述】:

我的UIButton 的一部分是UIImage,IOS 7 将其颜色从黑色变为蓝色。我尝试了这里提供的解决方案:将按钮类型更改为UIButtonTypeSystem,但这无济于事,图像仍然是蓝色的。这是我正在使用的通用代码:

UIButton *iWantPlan = [UIButton buttonWithType:UIButtonTypeSystem];
iWantPlan.frame = CGRectMake(self.view.bounds.size.width/2-bgImageWidth/2, planBg.frame.origin.y + planBg.frame.size.height + 20, bgImageWidth, bgImageWidth/4+5);
iWantPlan.titleLabel.font = [UIFont systemFontOfSize:20];
[iWantPlan addTarget:self action:@selector(goToPersonalDetails) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:iWantPlan];

iWantPlan.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
iWantPlan.imageView.frame = CGRectMake(bgImageWidth - 20, 10, 25, 25);
UIImage *viImage = [UIImage imageNamed:@"Icon_V.png"];
UIImage *viImageTap = [UIImage imageNamed:@"Icon_V_Tap.png"];
[iWantPlan setImage:viImage forState:UIControlStateNormal];
[iWantPlan setImage:viImageTap forState:UIControlStateSelected];

有解决办法吗? (顺便说一句,这真的很令人沮丧:)

【问题讨论】:

    标签: ios objective-c ios7 uibutton uiimage


    【解决方案1】:

    使用:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal 确定你没有蓝色背景:

    UIImage *viImage = [[UIImage imageNamed:@"Icon_V.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *viImageTap = [[UIImage imageNamed:@"Icon_V_Tap.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    

    来自Apple Documentation UIImageRenderingMode:
    始终绘制原始图像,而不将其视为模板:UIImageRenderingModeAlwaysOriginal

    另外,这可以帮助你:

    UIButton *iWantPlan = [UIButton buttonWithType:UIButtonTypeCustom];
    ...
    [iWantPlan setImage:viImageTap forState:UIControlStateHighlighted];
    

    【讨论】:

      【解决方案2】:

      只需将按钮的类型 UIButtonTypeSystem 更改为 UIButtonTypeCustom

      【讨论】:

        猜你喜欢
        • 2013-08-25
        • 1970-01-01
        • 2013-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多