Convert Apple Emoji (String) to UIImage

前端 未结 8 955
野的像风
野的像风 2020-12-12 21:53

I need all Apple Emojis.
I can get all the emojis and put them into a String by copying them from the site getemoji but in my app i need the emojis in the right

8条回答
  •  失恋的感觉
    2020-12-12 22:45

    Updated @Luca Angeletti answer for Swift 3.0.1

    extension String {
    
        func image() -> UIImage? {
            let size = CGSize(width: 30, height: 35)
            UIGraphicsBeginImageContextWithOptions(size, false, 0);
            UIColor.white.set()
            let rect = CGRect(origin: CGPoint(), size: size)
            UIRectFill(CGRect(origin: CGPoint(), size: size))
            (self as NSString).draw(in: rect, withAttributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 30)])
            let image = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return image
        }
    
    }
    

提交回复
热议问题