您的位置:首页 > 产品设计 > UI/UE

将UIButton 设置背景颜色 有点击highlight效果

2014-03-27 11:44 429 查看
首先写个UIImage的类别 为的就是要点击效果。PS:直接        [self.rightBtn setBackgroundColor:color]是没有点击高亮效果的。

@implementation UIImage (colorful)

+ (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;
}

@end

然后 
[self.rightBtn
setBackgroundImage:[UIImage
imageWithColor:[UIColor
color]] forState:UIControlStateNormal];就有点击高亮的效果了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uibutton