Giter VIP home page Giter VIP logo

roundcode's Introduction

RoundCode for iOS

License Swift 5 Twitter: @aslanyanhaik

RoundCode is custom circular QR code with lots of customization. Similar to Facebook messenger and Apple's App Clip Codes the RoundCode includes convenient camera scanner and decoder.

Different styles of RoundCode for iOS

Installation

Cocoapods:

pod 'RoundCode'

Swift Package Manager:

File > Swift Packages > Add Package Dependency

https://github.com/aslanyanhaik/RoundCode

Usage example

import framework

import RoundCode

Encoding

create coder and encode

let image = RCImage(message: "Hello World")
let coder = RCCoder()
do {
  imageView.image = try coder.encode(image)
} catch {
  //handle errors
}

You can also validate the messsage before encoding

let coder = RCCoder()
let isValidText = coder.validate("Hello world")

Decoding

Create instane of RCCameraViewController and handle the delegate

class ViewController: UIViewController, RCCameraViewControllerDelegate {
  
  func scan() {
    let cameraController = RCCameraViewController()
    cameraController.delegate = self
    present(cameraController, animated: true)
  }
  
  func cameraViewController(didFinishScanning message: String) {
    messageLabel.text = message
  }
}

You can also decode a UIImage like this

let coder = RCCoder()
do {
  messageLabel.text = try coder.decode(UIImage(named: code)!)
} catch {
  //handle errors
}

Appearance

You can change the appearance like this

var image = RCImage(message: "Hello world")
image.contentInsets = UIEdgeInsets(top: 8, left: 10, bottom: 4, right: 10)
image.attachmentImage = UIImage(named: "Profile")
image.size = 300
image.gradientType = .linear(angle: CGFloat.pi)
image.tintColors = [.red, .black]

If image is on dark background you should change scanning mode to darkBackground

let coder = RCCoder()
coder.scanningMode = .darkBackground

Advanced coding configuration

You can provide custom coding configuration in order to encode long text by reducing number of characters

let configuration = RCCoderConfiguration.shortConfiguration
let coder = RCCoder(configuration: configuration)
let configuration = RCCoderConfiguration(characters: " -abcdefghijklmnopqrstuvwxyz0123456789")
let coder = RCCoder(configuration: configuration)

⚠️ If you are encoding with custom configuration, then you should change the RCCameraViewController configuration ⚠️

let configuration = RCCoderConfiguration(characters: " -abcdefghijklmnopqrstuvwxyz0123456789")
let coder = RCCoder(configuration: configuration)
let camera = RCCameraViewController()
camera.coder = coder

Compatibility

Written in Swift 5 and requires Xcode 11.0

RoundCode is compatible with iOS 13.0+.

Screenshot of RoundCode for iOS

Author

License

Copyright 2020 Haik Aslanyan.

Licensed under MIT License: https://opensource.org/licenses/MIT

roundcode's People

Contributors

aslanyanhaik avatar

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.