iOS中UIImage和UIColor之间的转换

来源:互联网 发布:linux vi中查找字符串 编辑:程序博客网 时间:2024/06/11 04:28

  //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, [colorCGColor]);

   CGContextFillRect(context, rect);

    UIImage *Image =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

   return Image;

}



  //UIImageUIColor

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

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

    [cancelButton setBackgroundColor:[UIColorcolorWithPatternImage:image]];




     转载请注明出处:http://blog.csdn.net/sevenquan


0 0
原创粉丝点击