60
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftでQRコードを生成してみた

Posted at

SwiftでQRコードを生成してみました。

環境

  • Xcode 7.2.1
  • Swift 2.1.1

結果

image

コード


import UIKit
import CoreImage

var url = "http://www.yahoo.co.jp/"

// NSString から NSDataへ変換
let data = url.dataUsingEncoding(NSUTF8StringEncoding)!

// QRコード生成のフィルター
// NSData型でデーターを用意
// inputCorrectionLevelは、誤り訂正レベル
let qr = CIFilter(name: "CIQRCodeGenerator", withInputParameters: ["inputMessage": data, "inputCorrectionLevel": "M"])!


let sizeTransform = CGAffineTransformMakeScale(10, 10)
let qrImage = qr.outputImage!.imageByApplyingTransform(sizeTransform)

60
59
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
60
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?