IOS Swift 开发QRCore(二维码)实例详解
2019/7/9 23:05:14
本文主要是介绍IOS Swift 开发QRCore(二维码)实例详解,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、搭个界面
2、写代码
// // ViewController.swift // GeneratorQRCode // // Created by targetcloud on 2016/12/3. // Copyright © 2016年 targetcloud. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet weak var qrImg: UIImageView! @IBOutlet weak var qrContent: UITextView! @IBAction func generatorQRImg(_ sender: Any) { view.endEditing(true) let str = qrContent.text ?? "" let filter = CIFilter(name: "CIQRCodeGenerator") filter?.setDefaults() let data = str.data(using: String.Encoding.utf8) filter?.setValue(data, forKey: "inputMessage") filter?.setValue("M", forKey: "inputCorrectionLevel") var image = filter?.outputImage let transform = CGAffineTransform(scaleX: 10, y: 10)//处理成为一个高清图片 image = image?.applying(transform) var resultImage = UIImage(ciImage: image!) let centerImg = UIImage(named: "targetcloud.png") resultImage = mergeImage(resultImage, centerImg: centerImg!, drawSize:CGSize(width: 80, height: 80)) qrImg.image = resultImage } func mergeImage(_ sourceImage: UIImage, centerImg: UIImage,drawSize:CGSize) -> UIImage { let size = sourceImage.size UIGraphicsBeginImageContext(size) sourceImage.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) centerImg.draw(in: CGRect(x: (size.width - drawSize.width) * 0.5, y: (size.height - drawSize.height) * 0.5, width: drawSize.width, height: drawSize.height)) let resultImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return resultImage! } }
3、运行效果
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
这篇关于IOS Swift 开发QRCore(二维码)实例详解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-12Axios库资料:新手入门必读教程
- 2024-11-11Axios库项目实战:新手入门教程
- 2024-09-29Axios库教程:初学者必备指南
- 2024-08-29Axios库资料:新手入门指南与基本使用教程
- 2024-03-14system bios shadowed
- 2024-03-14gabios
- 2024-02-07iOS应用提交上架的最新流程
- 2024-02-06打包 iOS 的 IPA 文件
- 2023-12-07uniapp打包iOS应用并通过审核:代码混淆的终极解决方案 ?
- 2023-11-25uniapp IOS从打包到上架流程(详细简单) 原创