iOS中UIImage和UIColor之间的转换

  //UIColor 转UIImageit

- (UIImage*)imageWithColor: (UIColor*)colorio

{   im

 

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

    UIGraphicsBeginImageContext(rect.size);co

    CGContextRef context = UIGraphicsGetCurrentContext();radio

    CGContextSetFillColorWithColor(context, [color CGColor]);return

    CGContextFillRect(context, rect);context

    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]];

相关文章
相关标签/搜索