通过一个color创建一个image

使用的地方:

[_addButton setBackgroundImage:[UIImage imageWithColor:[[UIColor whiteColor] colorWithAlphaComponent:0.f]] forState:UIControlStateDisabled];




UIImage+Theme.m

==============================

+ (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 *bg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return bg;
}

使用的地方:

[UIImage imageWithColor:[[UIColor whiteColor] colorWithAlphaComponent:0.f]]


posted on 2015-07-21 10:45  封起De日子  阅读(132)  评论(0编辑  收藏  举报

导航