如何将UIView插入MSMessage?

时间:2019-08-27 14:42:22

标签: ios swift uiview imessage-extension msmessage

我正在尝试构建一个iMessage应用程序,该应用程序允许一个人按下将在iMessage文本字段中插入蓝色UIView的按钮。我不确定如何在iMessage文本字段中获得UIView

我尝试将UIView转换为UIImage,然后将其转换为MSSticker,但是,我需要贴纸的URL,因为我创建了{{ 1}}在代码中,我没有该路径的URL。

在这里,我创建UIImage

UIView

启用func createOval() -> UIImage { let blueOval = UIView(frame: CGRect(x: 5, y: 0, width: 10, height: 10)) blueOval.backgroundColor = .black let label = UILabel() label.text = "Hello" blueOval.addSubview(label) let image = blueOval.asImage() return tagImage } 转换的扩展名:

asImage()

如何将extension UIView { func asImage() -> UIImage { if #available(iOS 10.0, *) { let renderer = UIGraphicsImageRenderer(bounds: bounds) return renderer.image { rendererContext in layer.render(in: rendererContext.cgContext) } } else { UIGraphicsBeginImageContext(self.frame.size) self.layer.render(in:UIGraphicsGetCurrentContext()!) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return UIImage(cgImage: image!.cgImage!) } } } 插入到iMessage文本字段中?

0 个答案:

没有答案