//TextView转image
-(UIImage*) saveTextView
{
//1.设置大小
CGSize size = _maskText.size;//
_rect=_maskText.frame;
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions(size,NO,0);
// draw in context, you can use drawInRect/drawAtPoint:withFont:
// 2.设置text属性
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSShadow *shadow=[[NSShadow alloc]init];
shadow.shadowBlurRadius=2;//模糊度
shadow.shadowColor=[UIColor blackColor];
shadow.shadowOffset=CGSizeMake(1, 1);
//NSStrokeColorAttributeName:[UIColor blackColor],NSStrokeWidthAttributeName:@0.5
[_maskText.text drawInRect:CGRectMake(0, 0, size.width, size.height) withAttributes:dict];
//3. 转换为图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
_angle=0;
return image;
}
-(UIImage*) saveTextView
{
//1.设置大小
CGSize size = _maskText.size;//
_rect=_maskText.frame;
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions(size,NO,0);
// draw in context, you can use drawInRect/drawAtPoint:withFont:
// 2.设置text属性
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSShadow *shadow=[[NSShadow alloc]init];
shadow.shadowBlurRadius=2;//模糊度
shadow.shadowColor=[UIColor blackColor];
shadow.shadowOffset=CGSizeMake(1, 1);
//设置文字属性
//此处具体设置根据个人情况添加,具体设置请看iOS- 详解文本属性Attributes
//NSStrokeColorAttributeName:[UIColor blackColor],NSStrokeWidthAttributeName:@0.5
[_maskText.text drawInRect:CGRectMake(0, 0, size.width, size.height) withAttributes:dict];
//3. 转换为图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
_angle=0;
return image;
}