Skip to content

Instantly share code, notes, and snippets.

@matsuhisa
Created March 13, 2016 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsuhisa/71e8e6ad7d1edef70650 to your computer and use it in GitHub Desktop.
Save matsuhisa/71e8e6ad7d1edef70650 to your computer and use it in GitHub Desktop.
SwiftでQRコードを生成してみた ref: http://qiita.com/matsuhisa_h/items/91cdeeaf32553c3b23fb
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment