A QRCode generator written in Swift.

Overview

QRCode 🔳

Build Status Carthage compatible Swift 3.0

A QRCode generator written in Swift.

QRCode Example

Overview

Create a new QRCode representing a URL, a string or arbitrary data. The following examples all result in the same QRCode image.

// URL
let url = URL(string: "http://schuch.me")!
let qrCode = QRCode(url)
qrCode?.image

// String
let qrCode = QRCode("http://schuch.me")
qrCode?.image

// NSData
let data = "http://schuch.me".data(using: .isoLatin1)!
let qrCode = QRCode(data)
qrCode.image

Customize the output 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 above examples make use of the CIColor extension that ships with this project to create colors based on HEX strings.

UIImageView extension

For convenience, a UIImageView extension is provided to directly initialize an image view with an instance of QRCode.

let imageView = UIImageView(qrCode: qrCode)

Emoji alias

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")

Version Compatibility

Current Swift compatibility breakdown:

Swift Version Framework Version
3.0 2.x
2.3 1.x
2.2 0.x

Installation

Carthage

Add the following line to your Cartfile.

github "aschuch/QRCode"

Then run carthage update.

Cocoapods

Add the following line to your Podfile.

pod "QRCode"

Then run pod install with Cocoapods 0.36 or newer.

Manually

Just drag and drop the three .swift files in the QRCode folder into your project.

Tests

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

Todo

  • Snapshot Tests
  • Support transparent backgrounds

Contributing

  • 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

Contact

Feel free to get in touch.

Comments
  • Converting image to NSData return nil

    Converting image to NSData return nil

    Hey Guys,

    Trying to convert image to nsdata, but receive nil. Tried both PNG and JPEG.

    let qrc = QRCode("sample")
    let img = UIImagePNGRepresentation(qrc.image!) // img is nil 
    

    Please advice

    opened by ivanovvitaly 9
  • Fail when building with Carthage

    Fail when building with Carthage

    I received this error when i try to install this library with cathage.

    In cartfile: github "aschuch/QRCode"

    Error: *** Building scheme "QRCode" in Example.xcodeproj ** BUILD FAILED **

    The following build commands failed: CompileSwift normal x86_64 /project-path/Carthage/Checkouts/QRCode/QRCode/CIColorExtension.swift CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler (2 failures)

    opened by Sk92 5
  • Upgrade from Swift 3.0 to Swift 4.2, all tests finished successfully

    Upgrade from Swift 3.0 to Swift 4.2, all tests finished successfully

    I've upgraded the project to work with Swift 4.2, I have also checked the different targets and all of them compiled successfully with no warnings.

    Issue #59 - Swift 4.2 support.

    opened by gmotzespina 3
  • Swift 2.0 compatibility

    Swift 2.0 compatibility

    Hi,

    this library is awesome, but it didn't work out of the box with Xcode 7.0 beta and the new Swift 2.0 syntax. So I converted the syntax and the project, to comply with Xcode 7.0.

    Maybe you could leave the swift-2.0 branch, so that Xcode 7.0 users can use the following line in their Podfile:

    pod 'QRCode', :git => 'https://github.com/aschuch/QRCode', :branch => 'swift-2.0'
    

    Thanks, Marc

    opened by marcboeker 3
  • QRCode string encoding

    QRCode string encoding

    Is there a specific reason why the initialisers for string and NSURL both encode the input as latin1 instead of UTF-8?

    public init?(_ string: String) {
            if let data = string.dataUsingEncoding(NSISOLatin1StringEncoding) {
                self.data = data
            } else {
                return nil
            }
        }
    
    public init?(_ url: NSURL) {
        if let data = url.absoluteString.dataUsingEncoding(NSISOLatin1StringEncoding) {
            self.data = data
        } else {
            return nil
        }
    }
    
    opened by Querschlag 2
  • IOS 7 code still blurry

    IOS 7 code still blurry

    I placed the high error correction in and the code still appears blurry.

        var qrImage = UIImageView(frame: CGRectMake((lpScroll.frame.size.width - qrWidth) / 2, ish, qrWidth, qrWidth))
        let url = NSURL(string: url4Sharing)
        var qrCode = QRCode(url!)
        qrCode?.errorCorrection = QRCode.ErrorCorrection.High
        qrCode?.color = CIColor(color: UIColor.cloudsColor())
        qrCode?.backgroundColor = CIColor(color: darkColor)
        qrCode?.size = CGSize(width: qrWidth * 2, height: qrWidth * 2)
        qrImage.image = qrCode?.image
        lpScroll.addSubview(qrImage)
    
    opened by v1n2e7t 2
  • You may want to add this to the README

    You may want to add this to the README

    To build for Swift 3.0 for the time being you need to add this to your Podfile

    `pod 'QRCode', :git => "[email protected]:aschuch/QRCode.git", :branch => "swift3.0"`
    
    opened by alimoeeny 1
  • fix: capture image with device scale.

    fix: capture image with device scale.

    I encountered a problem that the result QRCode image is blurred. So this commit simply capture the image with device scale solved that problem, and has no effect to other usages.

    opened by 5d 1
  • how about add NSUrl,String extension

    how about add NSUrl,String extension

    i think using extension to invoke have a better experience. like: stringA.QRImage() this method could have some default parameters,like size or something else.

    if you agree with this , I can spend some time work on it,create a pull request

    opened by lacklock 1
  • Created images not working with UIViewContentModeScaleAspectFit

    Created images not working with UIViewContentModeScaleAspectFit

    The created image gets streched even when using UIViewContentModeScaleAspectFit on a UIImageView.

    Fixed it by adding another conversion step (CIImage -> CGImage -> UIImage). https://github.com/Querschlag/QRCode/commit/f603d590bda07ac81f9e3cdd09ebef6d53853e41

    Update: This also fixes image preview in the debugger.

    opened by Querschlag 1
  • Swift 2 compat changes

    Swift 2 compat changes

    This gets the code compiling on current Xcode. A lot of the affected changes are optional <-> non-optional.

    This won't be compatible with older versions; for that such changes will need to be guarded with "if foo is Bar?" and the like.

    opened by jj101k 1
Releases(2.0)
Owner
Alexander Schuch
Swift developer. Classic Mini driver.
Alexander Schuch
Random image generator built with Swift

Ody Ody is an easy to use random image generator built with Swift. Perfect for placeholders! Built with [Silo] silojq, [LoremPixel] images, and FillDu

Jose Quintero 46 Dec 14, 2020
iOS hashtag generator, using image analysis and discovery

Tagger Description Want to be popular on some social network easily? Use Tagger to make your account content more popular and to raise your popularity

Ivan Magda 44 Dec 17, 2022
A random photo generator from unsplash for iOS

Random Photo App for IOS How it works It is a random photo generator from unsplash. Everytime you press the button, a random photo appears and the bac

Stefan Istoc 2 Feb 2, 2022
React-native-image-generator - Library to generate images from layers

react-native-image-generator Library for generate images from other images Insta

Evgeny Usov 13 Nov 16, 2022
SwiftUI App Icon Generator App for iOS & macOS Catalyst

SwiftUI App Icon Generator App for iOS & macOS Catalyst Generate Asset Icons easily to your iPhone, iPad, Mac, and Apple Watch Features The app has se

Alfian Losari 21 Sep 14, 2022
Agrume - 🍋 An iOS image viewer written in Swift with support for multiple images.

Agrume An iOS image viewer written in Swift with support for multiple images. Requirements Swift 5.0 iOS 9.0+ Xcode 10.2+ Installation Use Swift Packa

Jan Gorman 601 Dec 26, 2022
FacebookImagePicker is Facebook album photo picker written in Swift.

Features • Installation • Usage • Translation • License GBHFacebookImagePicker is Facebook's album photo picker written in Swift, built to provide a s

Florian Gabach 231 Dec 17, 2022
A lightweight generic cache for iOS written in Swift with extra love for images.

Haneke is a lightweight generic cache for iOS and tvOS written in Swift 4. It's designed to be super-simple to use. Here's how you would initalize a J

Haneke 5.2k Dec 11, 2022
A lightweight and fast image loader for iOS written in Swift.

ImageLoader ImageLoader is an instrument for asynchronous image loading written in Swift. It is a lightweight and fast image loader for iOS. Features

Hirohisa Kawasaki 293 Nov 24, 2022
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

Evgenii Neumerzhitckii 330 Sep 9, 2022
Fast and simple OCR library written in Swift

⛔️ This Project is deprecated and no longer gets maintained! Please use Apple's Vision framework instead of SwiftOCR. It is very fast, accurate and mu

Nicolas Camenisch 4.5k Dec 29, 2022
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.

SkyFloatingLabelTextField SkyFloatingLabelTextField is a beautiful, flexible and customizable implementation of the space saving "Float Label Pattern"

Skyscanner 4k Jan 3, 2023
XAnimatedImage is a performant animated GIF engine for iOS written in Swift based on FLAnimatedImage

XAnimatedImage is a performant animated GIF engine for iOS written in Swift based on FLAnimatedImage. An illustration is shown below: Features Plays m

Khaled Taha 561 Sep 9, 2022
Rounded async imageview downloader lightly cached and written in Swift

PASImageView ============ **Rounded async imageview downloader lightly cached and written in Swift 3 ** Objective-C version here Snapshot Usage //XIB

Pierre Abi-aad 173 Nov 6, 2022
Image picker with custom crop rect for iOS written in Swift (Ported over from GKImagePicker)

WDImagePicker Ever wanted a custom crop area for the UIImagePickerController? Now you can have it with WDImagePicker. Just set your custom crop area a

Wu Di 96 Dec 19, 2022
A simple macOS app to read code from images, written purely in Swift using Vision Framework.

CodeReader A simple macOS app to read code from images, written purely in Swift using Vision Framework. Usage Drag an image Click the convert button R

Md Ibrahim Hassan 44 Nov 20, 2022
In-app screen recording using ReplayKit in iOS. Written in Swift 5 on Xcode 12.3

In-App-ScreenRecording-iOS In-app screen recording using ReplayKit in iOS. Written in Swift 5 on Xcode 12.3 Features: Recording application screen onl

Ahmed Abdelkarim 4 Dec 23, 2022
Instant camera hybrid with multiple effects and filters written in Swift.

Kontax Cam Download on the app store! No longer on the app store Kontax Cam is an instant camera built 100% using Swift for iOS. You can take your pho

Kevin Laminto 108 Dec 27, 2022
iOS photo gallery written in Swift

SwiftPhotoGallery Overview A full screen photo gallery for iOS and tvOS written in Swift. Photos can be panned and zoomed (iOS only) Pinch to zoom (iO

Justin Vallely 271 Dec 17, 2022