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

iOS中UIImage和UIColor之间的转换

2015-12-29 17:13 549 查看
//UIColor 转UIImage
- (UIImage*)imageWithColor: (UIColor*)color
{

CGRect rect=CGRectMake(0.0f,
0.0f, 100.0f,
50.0f);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context =
UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color
CGColor]);

CGContextFillRect(context, rect);

UIImage *Image =
UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return Image;
}

//UIImage转UIColor

UIButton *Button = [[UIButton
alloc] initWithFrame:CGRectMake(20,
200,
100, 50)];

UIImage *image = [UIImage
imageNamed:@"radio_bn.png"];

[cancelButton setBackgroundColor:[UIColor
colorWithPatternImage:image]];

转载请注明出处:http://blog.csdn.net/sevenquan
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: