//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]];
时间: 2024-10-13 12:58:13