Created
June 13, 2015 14:50
-
-
Save yutelin/8d3daeb8a33d5786cb6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Reference: http://stackoverflow.com/questions/12051118/is-there-a-way-to-generate-qr-code-image-on-ios#comment48548881_22296488 | |
import Foundation | |
import UIKit | |
extension String{ | |
var qrcode: CIImage { | |
//let data = self.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false) | |
let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) | |
let filter = CIFilter(name: "CIQRCodeGenerator") | |
filter.setValue(data, forKey: "inputMessage") | |
filter.setValue("Q", forKey: "inputCorrectionLevel") | |
let image = filter.outputImage | |
//fix blurry: http://stackoverflow.com/questions/12051118/is-there-a-way-to-generate-qr-code-image-on-ios#comment48548881_22296488 | |
let transform = CGAffineTransformMakeScale(5.0, 5.0) | |
return image.imageByApplyingTransform(transform) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment