// Text bounds NSString* text = @"Big Button"; UIFont* font = [UIFont boldSystemFontOfSize:18]; CGSize size = [text sizeWithFont:font]; // Rendering context UIGraphicsBeginImageContext(size); CGContextRef context = UIGraphicsGetCurrentContext(); // Set colors CGContextSetFillColorWithColor(context, [[UIColor greenColor] CGColor]); CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]); // Render [text drawInRect:CGRectMake(0, 0, size.width, size.height) withFont:font]; // Create image and release context UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); ·
http://www.mlsite.net/blog/?p=234// Text bounds NSString* text = @"Big Button"; UIFont* font = [UIFont boldSystemFontOfSize:18]; CGSize size = [text sizeWithFont:font]; // Rendering context UIGraphicsBeginImageContext(size); CGContextRef context = UIGraphicsGetCurrentContext(); // Set colors CGContextSetFillColorWithColor(context, [[UIColor greenColor] CGColor]); CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]); // Render [text drawInRect:CGRectMake(0, 0, size.width, size.height) withFont:font]; // Create image and release context UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); ·
http://www.mlsite.net/blog/?p=234