Convert Apple Emoji (String) to UIImage

前端 未结 8 975
野的像风
野的像风 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:43

    Updated version of @Luca Angeletti's answer using UIGraphicsImageRenderer:

    extension String {
        func image() -> UIImage? {
            let size = CGSize(width: 100, height: 100)
            let rect = CGRect(origin: CGPoint(), size: size)
            return UIGraphicsImageRenderer(size: size).image { (context) in
                (self as NSString).draw(in: rect, withAttributes: [.font : UIFont.systemFont(ofSize: 100)])
            }
        }
    }
    

提交回复
热议问题