Code Monkey home page Code Monkey logo

qrcode's Introduction

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.

qrcode's People

Contributors

5d avatar aschuch avatar basthomas avatar jiverson avatar pepe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qrcode's Issues

Logo on the middle ?

Hello,

This a very nice work, but I have one question, it is possible to put a logo in the middle of the QR Code ?

Thank's in advance.

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

Crash issue on Xcode8 with swift2.3

Hi,

Below code will be crashed on Xcode8

guard let cgImage = CIContext(options: nil).createCGImage(self, fromRect: self.extent) else { return nil }

'NSInvalidArgumentException', reason: '-[CIContext initWithOptions:]: unrecognized selector

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
    }
}

Crashes on iOS8 (when build with Xcode 8 / Swift 3)

Crash when using CIContext(options:) in CIImageExtensions.swift line 21. Seems to be an issue of Xcode 8 which is having issues translating the Swift 3 options: notation into contextWithOptions: (instead of initWithOptions). Writing a second helper extension in Obj-C would be a workaround.

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)

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)

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

Maximum capacity

Hi,

What is the maximum capacity that can be encoded for an ASCII encoded string?

Thanks,
:panos

Error correction level

Hi,

What is the error correction level used for the generated qr codes?

Is there a way to specify it?

Thanks,
:panos

Submit to app Store

i guess you need to app a key to info.plist for Privacy - Media Library Usage Description
app Binary was invalid till i add to my info.plist the Error was missing this Key "NSPhotoLibraryUsageDescription"

please put a hint in readme file as it required from iOS 10

compiler error

branch: Swift 2.2
xcode 7.3.x

Steps to repro:

  1. clone
  2. switch to branch 2.2
  3. open example project in xcode and build

actual:
Github/QRCode/QRCode/CIImageExtension.swift:21:15: Initializer for conditional binding must have Optional type, not 'CGImage'

/Github/QRCode/QRCode/QRCode.swift:63:41: Cannot use optional chaining on non-optional value of type 'String'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.