1硫狞、字符串轉(zhuǎn)換成圖片
- (UIImage *)imageFromString:(NSString *)string attributes:(NSDictionary *)attributes size:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
[string drawInRect:CGRectMake(0, 0, size.width, size.height) withAttributes:attributes];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
2焕阿、view 轉(zhuǎn)換成圖片
- (UIImage *)imageForView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);
if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
else
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者