做UI的时候我们可能想给某个Label添加一个背景图片,但查看的时候会发现好像只有设置背景颜色的方法,不过我们也可以通过这种方式来解决:
UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"itemkaung2.png"]];
[myLabel setBackgroundColor:color];
color转img
- - (UIImage *) createImageWithColor: (UIColor *) color
- {
-
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); -
UIGraphicsBeginImageCont ext(rect.size); -
CGContextRef context = UIGraphicsGetCurrentCont ext(); -
CGContextSetFillColorWit hColor(context, [color CGColor]); -
CGContextFillRect(context, rect); -
-
UIImage *theImage = UIGraphicsGetImageFromCu rrentImageContext(); -
UIGraphicsEndImageContex t(); -
return theImage; - }