我的代碼是如何以編程方式更改文本的顏色?
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1
{
int w = img.size.width;
int h = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];
CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 255, 255, 255, 2);
CGContextShowTextAtPoint(context, 10, 170, text, strlen(text));
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
我們如何才能改變編程文本的顏色? 答案將不勝感激!
這不是'CGContextSetRGBFillColor'函數的參數範圍。 – 2010-03-24 15:27:52
你說得對,0-1.0。我會編輯它。 – Adolfo 2010-03-25 15:53:16
非常感謝!現在我懂了。 – isarathg 2010-03-26 08:05:41