我试图将base64字符串放入图像视图中我已尝试过很多方法但是没有工作,所以我先做的是将我的字符串编码为base64,之后我试图将base64分配给一个图像,但是当代码块完成时,代码行 qrCodeImageView.image = image 使我返回零,你对我有什么了解吗? 39;做错了。提前致谢
类QRCodeViewController:UIViewController {
@IBOutlet weak var qrCodeImageView: UIImageView!
var qrCodeConverted: String?
override func viewDidLoad() {
super.viewDidLoad()
print("QRCode", APIManager.sharedInstance.bas64 ?? "")
let longstring = APIManager.sharedInstance.qrCodee
let data = (longstring)?.data(using: String.Encoding.utf8)
let base64 = data!.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
print("base64 ", base64)
if let decodedData = Data(base64Encoded: base64, options: .ignoreUnknownCharacters) {
let image = UIImage(data: decodedData)
qrCodeImageView.image = image
}
}