//文字生成图片
-(UIImage *)imageFromText:(NSString *)contentStr withFont: (UIFont *)font
{
//确定文字的size
CGFloat imageWidth = [UIScreen mainScreen].bounds.size.width - 20;
CGSize contentSize = [contentStr boundingRectWithSize:CGSizeMake(imageWidth, 0) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : font} context:nil].size;
UIGraphicsBeginImageContextWithOptions(contentSize,NO,0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetCharacterSpacing(ctx, 10);
CGContextSetTextDrawingMode (ctx, kCGTextFill);
CGContextSetRGBFillColor (ctx, 0.1, 0.2, 0.3, 1); // 6
CGContextSetRGBStrokeColor (ctx, 0, 0, 0, 1);
CGRect rect = CGRectMake(0, 0, contentSize.width, contentSize.height );
[contentStr drawInRect:rect withAttributes:@{NSFontAttributeName : font}];
// transfer image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}