通过颜色来生成一个纯色图片

通过颜色来生成一个纯色图片
1
2
3
4
5
6
7
8
9
10
- (UIImage *)buttonImageFromColor:(UIColor *)color{
    CGRect rect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

posted on 2014-07-30 14:01  恒山之阳  阅读(909)  评论(0编辑  收藏  举报

导航