Skip to content

1D and 2D barcodes reader and generators for iOS 8 with delightful controls. Now Swift.

License

Notifications You must be signed in to change notification settings

SanManuelMobile/Barcode-Generator

 
 

Repository files navigation

Forked from yeahdongcn/RSBarcodes_Swift

Allows you to generate the same set of barcode images for displaying and sharing.

TODO

Generators

  • Code39
  • Code39Mod43
  • ExtendedCode39
  • Code93
  • Code128
  • UPCE
  • EAN FAMILIY (EAN8 EAN13 ISBN13 ISSN13)
  • ITF14
  • Interleaved2of5
  • DataMatrix
  • PDF417
  • QR
  • Aztec
  • Views

Installation

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter https://github.com/SanManuelMobile/Barcode-Generator to the text field.

Usage

How to Use Generator and How to Use Reader

Generators

First, import the following frameworks:

import BarcodeGenerator
import AVFoundation

Then, use the generator to generate a barcode. For example:

RSUnifiedCodeGenerator.shared.generateCode("2166529V", machineReadableCodeObjectType: AVMetadataObjectTypeCode39Code)

It will generate a UIImage instance if the 2166529V is a valid code39 string. For AVMetadataObjectTypeCode128Code, you can change useBuiltInCode128Generator to false to use my implementation (AutoTable for code128).

P.S. There are 4 tables for encoding a string to code128, TableA, TableB, TableC and TableAuto; the TableAuto is always the best choice, but if one has specific requirements, try this:

RSCode128Generator(codeTable: .A).generateCode("123456", machineReadableCodeObjectType: AVMetadataObjectTypeCode128Code)

Example of these simple calls can be found in the test project.

Validator

To validate codes:

let isValid = RSUnifiedCodeValidator.shared.isValid(code, machineReadableCodeObjectType: AVMetadataObjectTypeEAN13Code)

Image helpers

Use RSAbstractCodeGenerator.resizeImage(source: UIImage, scale: CGFloat) to scale the generated image.

Use RSAbstractCodeGenerator.resizeImage(source: UIImage, targetSize: CGSize, contentMode: UIViewContentMode) to fill/fit the bounds of something to the best capability and don't necessarily know what scale is too much to fill/fit, or if the UIImageView itself is flexible.

Miscellaneous

The Swift Programming Language 中文版

Online version generated using GitBook

License

The MIT License (MIT)

Copyright (c) 2012-2014 P.D.Q.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

1D and 2D barcodes reader and generators for iOS 8 with delightful controls. Now Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%