iOS
NSAttributedString को UIImage में बदलें
खोज…
NSAttributedString से UIImage रूपांतरण
उद्देश्य सी
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Hello. That is a test attributed string."];
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(3,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(10,7)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)];
UIImage *customImage = [self imageFromAttributedString:str];
फ़ंक्शन imageFromAttributedString
नीचे परिभाषित किया गया है:
- (UIImage *)imageFromAttributedString:(NSAttributedString *)text
{
UIGraphicsBeginImageContextWithOptions(text.size, NO, 0.0);
// draw in context
[text drawAtPoint:CGPointMake(0.0, 0.0)];
// transfer image
UIImage *image = [UIGraphicsGetImageFromCurrentImageContext() imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIGraphicsEndImageContext();
return image;
}
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow