Swift Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 | func imageFromText(#text:String,font:UIFont,color:UIColor)->UIImage { let size : CGSize = (text as NSString).sizeWithAttributes([NSFontAttributeName: font]) UIGraphicsBeginImageContextWithOptions(size, false, 0.0) (text as NSString).drawAtPoint(CGPointMake(0.0, 0.0), withAttributes: [NSFontAttributeName: font, NSForegroundColorAttributeName:color]) let image : UIImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image } |
Keine Kommentare:
Kommentar veröffentlichen