A QRCode generator written in Swift.
Create a new QRCode representing a NSURL
, a string or arbitrary data.
The following examples all result in the same QRCode image.
// NSURL
let url = NSURL(string: "http://schuch.me")
qrCode = QRCode(url)
qrCode?.image
// String
let qrCode = QRCode("http://schuch.me")
qrCode?.image
// NSData
let data = "http://schuch.me".dataUsingEncoding(NSISOLatin1StringEncoding)
let qrCode = QRCode(data)
qrCode.image
Make sure to declare your
QRCode
instance as a variable in order make use of the following features.
Adjust Output Size
Change the output size of the QRCode output image via the size
property.
qrCode.size = CGSize(width: 300, height: 300)
qrCode.image // UIImage (300x300)
Color
Modify the colors of the QRCode output image via color
and backgroundColor
properties.
qrCode.color = CIColor(rgba: "16a085")
qrCode.backgroundColor = CIColor(rgba: "000")
qrCode.image // UIImage (green QRCode color and black background)
Note: The obove examples make use of the
CIColor
extension that ships with this project to create colors based on HEX strings.
For convenience, a UIImageView
extension is provided to directly initialize an image view with an instance of QRCode
.
let imageView = UIImageView(qrCode: qrCode)
In case you love emoji as much as I do, make sure to create your QRCode
instance using the 🔳 typealias.
let qrCode = 🔳("http://example.com")
Add the following line to your Cartfile.
github "aschuch/QRCode"
Then run carthage update
.
NOTE: Cocoapods does not officially support Swift projects yet. Make sure you have Cocoapods 0.36 beta installed by running gem install cocoapods --pre
.
Add the following line to your Podfile.
pod "QRCode", "~> 0.1"
Then run pod install
with Cocoapods 0.36 or newer.
Just drag and drop the three .swift
files in the QRCode
folder into your project.
Open the Xcode project and press ⌘-U
to run the tests.
Alternatively, all tests can be run from the terminal using xctool.
xctool -scheme QRCodeTests -sdk iphonesimulator test
- Snapshot Tests
- Support transparent backgrounds
- Create something awesome, make the code better, add some functionality, whatever (this is the hardest part).
- Fork it
- Create new branch to make your changes
- Commit all your changes to your branch
- Submit a pull request
Feel free to get in touch.
- Website: http://schuch.me
- Twitter: @schuchalexander