【问题标题】:iOS - UIButton shows touch on highlight coloriOS - UIButton 显示触摸高亮颜色
【发布时间】:2012-01-03 00:37:35
【问题描述】:

我想知道在 UIButton 上启用 showTouchOnHighlighted 选项时是否可以更改发光颜色。 谢谢

【问题讨论】:

标签: ios colors uibutton highlight


【解决方案1】:

据我所知,我们无法更改按钮的颜色。但是你可以改变它的形象。您可以为所有可用的按钮状态设置图像。

- (void)setImage:(UIImage *)image forState:(UIControlState)state

您可以在此处找到有关相同内容的更多详细信息:UIButton Class Reference

根据您的要求选择您的状态为 UIControlStateNormal、UIControlStateSelected 或 UIControlStateHighlighted

【讨论】:

    【解决方案2】:

    可以使用 UIColor 创建图像,因此我们需要添加类似的内容:

        [button setBackgroundImage:[self imageWithColor:[UIColor lightGrayColor]] 
    forState:UIControlStateHighlighted];
    

    -

    - (UIImage *)imageWithColor:(UIColor *)color
    {
        CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
    
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return image;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-30
      • 2014-01-29
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      相关资源
      最近更新 更多