Skip to content

EFPrefix/EFQRCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Repository files navigation

Compatible with all Platforms

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, inspired byqrcode.Based onCoreGraphics,CoreImage,andImageIO,EFQRCode provides you a better way to handle QRCode in your app, no matter if it is on iOS, macOS, watchOS, and/or tvOS. You can integrate EFQRCode through CocoaPods, Carthage, and/or Swift Package Manager.

Tiếng Trung giới thiệu

Examples

Demo Projects

App Store

You can click theApp Storebutton below to download demo, support iOS, tvOS and watchOS:

You can also click theMac App Storebutton below to download demo for macOS:

Compile Demo Manually

To run the example project manually, clone the repo, demos are in the 'Examples' folder, remember run commandsh Startup.shin terminal to get all dependencies first, then openEFQRCode.xcworkspacewith Xcode and select the target you want, run.

Or you can run the following command in terminal:

git clone git@github:EFPrefix/EFQRCode.git;cdEFQRCode;sh Startup.sh;open'EFQRCode.xcworkspace'

Requirements

Version Needs
1.x Xcode 8.0+
Swift 3.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+
4.x Xcode 9.0+
Swift 4.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
5.x Xcode 11.1+
Swift 5.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
6.x Xcode 12.0+
latest Swift
iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+

Installation

CocoaPods

EFQRCode is available throughCocoaPods.To install it, simply add the following line to your Podfile:

pod'EFQRCode','~> 6.2.2'

Then, run the following command:

$ pod install

Carthage

IMPORTANT:thisworkaroundis necessary for Carthage to somewhat work in Xcode 12.

Carthageis a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage withHomebrewusing the following command:

$ brew update
$ brew install carthage

To integrate EFQRCode into your Xcode project using Carthage, specify it in yourCartfile:

github "EFPrefix/EFQRCode" ~> 6.2.2

Runcarthage updateto build the framework and drag the builtEFQRCode.frameworkinto your Xcode project.

Swift Package Manager

TheSwift Package Manageris a tool for automating the distribution of Swift code and is integrated into the Swift compiler.

Once you have your Swift package set up, adding EFQRCode as a dependency is as easy as adding it to thedependenciesvalue of yourPackage.swift.

dependencies:[
.package(url:"https://github /EFPrefix/EFQRCode.git",.upToNextMinor(from:"6.2.2"))
]

Quick Start

1. Import EFQRCode

Import EFQRCode module where you want to use it:

import EFQRCode

2. Recognition

A String Array is returned as there might be several QR Codes in a singleCGImage:

iflettestImage=UIImage(named:"test.png")?.cgImage{
letcodes=EFQRCode.recognize(testImage)
if!codes.isEmpty{
print("There are\(codes.count)codes")
for(index,code)in codes.enumerated(){
print("The content of QR Code\(index)is\(code).")
}
}else{
print("There is no QR Codes in testImage.")
}
}

3. Generation

Create QR Code image, basic usage:

Parameter Description
content REQUIRED,content of QR Code
size Width and height of image
backgroundColor Background color of QRCode
foregroundColor Foreground color of QRCode
watermark Background image of QRCode
ifletimage=EFQRCode.generate(
for:"https://github /EFPrefix/EFQRCode",
watermark:UIImage(named:"WWF")?.cgImage
){
print("Create QRCode image success\(image)")
}else{
print("Create QRCode image failed!")
}

Result:

4. Generation from GIF

UseEFQRCode.generateGIFto create GIF QRCode.

Parameter Description
generator REQUIRED,anEFQRCodeGeneratorinstance with other settings
data REQUIRED,encoded input GIF
delay Output QRCode GIF delay, emitted means no change
loopCount Times looped in GIF, emitted means no change
ifletqrCodeData=EFQRCode.generateGIF(
using:generator,withWatermarkGIF:data
){
print("Create QRCode image success.")
}else{
print("Create QRCode image failed!")
}

You can get more information from the demo, result will like this:

5. Next

Learn more fromUser Guide.

Recommendations

  1. Please select a high contrast foreground and background color combinations;
  2. To improve the definition of QRCode images, increasesize,or scale up usingmagnification(instead);
  3. Magnification too high/size too large/contents too long may cause failure;
  4. It is recommended to test the QRCode image before put it into use;
  5. You can contact me if there is any problem, bothIssueandPull requestare welcome.

PS of PS: I wish you can click theStarbutton if this tool is useful for you, thanks, QAQ...

Other Platforms/Languages

Platforms/Languages Link
Objective-C https://github /z624821876/YSQRCode
Java https://github /SumiMakito/AwesomeQRCode
JavaScript https://github /SumiMakito/Awesome-qr.js
Kotlin https://github /SumiMakito/AwesomeQRCode-Kotlin
Python https://github /sylnsfar/qrcode

Contributors

This project exists thanks to all the people who already contributed to us. [Contribute]

Backers

If you think this project has brought you help, you can buy me a cup of coffee. If you like this project and are willing to provide further support for it's development, you can choose to becomeBackerinOpen Collective.Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Other

Part of the pictures in the demo project and guide come from the internet. If there is any infringement of your legitimate rights and interests, please contact us to delete.

Contact

Email:[email protected]

License

EFQRCode is available under the MIT license. See the LICENSE file for more info.