EFQRCodeGenerator

@objcMembers
public class EFQRCodeGenerator : NSObject

Class for generating QR code images.

  • Update the property specified the key path to have a new value.

    Declaration

    Swift

    @discardableResult
    @inlinable
    public func with<T>(_ keyPath: ReferenceWritableKeyPath<EFQRCodeGenerator, T>,
                        _ newValue: T) -> EFQRCodeGenerator

    Parameters

    keyPath

    A property to update.

    newValue

    The new value for the specified property.

    Return Value

    self, allowing chaining.

Content Parameters

  • Content to include in the generated QR Code.

    Important

    Limited to at most 1273 characters.

    Note

    The density of the QR-lattice increases with the increases of the content length.

    Declaration

    Swift

    public var content: String? { get set }
  • Sets the generator to generate for content using the specified encoding.

    Declaration

    Swift

    @discardableResult
    public func withContent(_ content: String, encoding: String.Encoding? = nil) -> EFQRCodeGenerator

    Parameters

    content

    The new content to generate QR code for.

    encoding

    The encoding to use for generating data from content.

    Return Value

    self, allowing chaining.

  • Encoding for content.

    Declaration

    Swift

    public var contentEncoding: String.Encoding { get set }
  • Sets the generator to use the specified encoding.

    Declaration

    Swift

    @discardableResult
    public func withContentEncoding(_ encoding: String.Encoding) -> EFQRCodeGenerator

    Parameters

    encoding

    The encoding to use for generating data from content.

    Return Value

    self, allowing chaining.

  • Level of error tolerance.

    • L 7%
    • M 15%
    • Q 25%
    • H 30%(Default)

    Declaration

    Swift

    public var inputCorrectionLevel: EFInputCorrectionLevel { get set }
  • Sets the generator to use the specified input correction level.

    Declaration

    Swift

    @discardableResult
    public func withInputCorrectionLevel(_ inputCorrectionLevel: EFInputCorrectionLevel) -> EFQRCodeGenerator

    Parameters

    inputCorrectionLevel

    level of error-tolerant rate.

    Return Value

    self, allowing chaining.

Style Parameters

  • Color mode of QR Code, defaults to nil.

    Declaration

    Swift

    public var mode: EFQRCodeMode? { get set }
  • Sets the generator to use the specified coloring mode.

    Declaration

    Swift

    @discardableResult
    public func withMode(_ mode: EFQRCodeMode?) -> EFQRCodeGenerator

    Parameters

    mode

    The new coloring mode to use.

    Return Value

    self, allowing chaining.

  • Size of the QR code, defaults to 256 by 256.

    Note

    Will be overridden by non-nil magnification parameter.

    Declaration

    Swift

    public var size: EFIntSize { get set }
  • Sets the generator to use the specified size.

    Declaration

    Swift

    @discardableResult
    public func withSize(_ size: EFIntSize) -> EFQRCodeGenerator

    Parameters

    size

    The width and height desired.

    Return Value

    self, allowing chaining.

  • The ratio of actual size to the smallest possible size, defaults to nil.

    Note

    Any non-nil value overrides the size parameter. If you already have a desired size in mind, we have two helpers methods at your disposal to calculate the magnification that results in the closet dimension:
    let generator = EFQRCodeGenerator(...)
    
    // get max magnification where size ≤ desired size
    if let maxMagnification = generator
        .maxMagnification(lessThanOrEqualTo: desiredSize) {
        generator.magnification = EFIntSize(
            width: maxMagnification,
            height: maxMagnification
        )
    }
    // or get min magnification where size ≥ desired size
    if let minMagnification = generator
        .minMagnification(greaterThanOrEqualTo: desiredSize) {
        generator.magnification = EFIntSize(
            width: minMagnification,
            height: minMagnification
        )
    }
    
    // then generate
    generator.generate()
    

    Declaration

    Swift

    public var magnification: EFIntSize? { get set }
  • Sets the generator to use the specified magnification.

    Declaration

    Swift

    @discardableResult
    public func withMagnification(_ magnification: EFIntSize?) -> EFQRCodeGenerator

    Parameters

    magnification

    The desired scale factor in comparison to the intrinsic size. See magnification for more details on how to translate your desired size to the closest magnification.

    Return Value

    self, allowing chaining.

  • Background color, defaults to white.

    Declaration

    Swift

    public var backgroundColor: CGColor { get set }
  • Foreground color (for code points), defaults to black.

    Declaration

    Swift

    public var foregroundColor: CGColor { get set }
  • Sets the generator to use the specified CIColors.

    Declaration

    Swift

    @discardableResult
    @objc(withCIColorsForBackgroundColor:foregroundColor:)
    public func withColors(backgroundColor: CIColor, foregroundColor: CIColor) -> EFQRCodeGenerator

    Parameters

    backgroundColor

    The background CIColor. If conversion to CGColor fails, will use white instead.

    foregroundColor

    The foreground CIColor for code points. If conversion to CGColor fails, will use black instead.

    Return Value

    self, allowing chaining.

  • Sets the generator to use the specified CGColors.

    Declaration

    Swift

    @discardableResult
    @objc(withCGColorsForBackgroundColor:foregroundColor:)
    public func withColors(backgroundColor: CGColor, foregroundColor: CGColor) -> EFQRCodeGenerator

    Parameters

    backgroundColor

    The background CGColor.

    foregroundColor

    The foreground CGColor for code points.

    Return Value

    self, allowing chaining.

  • Icon image in the center of QR code image, defaults to nil.

    Declaration

    Swift

    public var icon: CGImage? { get set }
  • Size of the icon image, defaults to 20% of size if nil.

    Declaration

    Swift

    public var iconSize: EFIntSize? { get set }
  • Sets the generator to use the specified icon in the specified size.

    Declaration

    Swift

    @discardableResult
    public func withIcon(_ icon: CGImage?, size: EFIntSize?) -> EFQRCodeGenerator

    Parameters

    icon

    Icon image in the center of QR code.

    size

    Size of the icon image, nil means to 20% of QR code size.

    Return Value

    self, allowing chaining.

  • Background watermark image, defaults to nil.

    Declaration

    Swift

    public var watermark: CGImage? { get set }
  • How to position and size the watermark, defaults to EFWatermarkMode.scaleAspectFill.

    Declaration

    Swift

    public var watermarkMode: EFWatermarkMode { get set }
  • Sets the generator to use the specified watermark (and mode).

    Declaration

    Swift

    @discardableResult
    public func withWatermark(_ watermark: CGImage?, mode: EFWatermarkMode? = nil) -> EFQRCodeGenerator

    Parameters

    watermark

    The background watermark image.

    mode

    How to position and size the watermark, nil (the default) means use the current watermarkMode.

    Return Value

    self, allowing chaining.

  • Foreground point offset, defaults to 0.

    Important

    Generated QR code might be hard to recognize with non-zero values.

    Declaration

    Swift

    public var pointOffset: CGFloat { get set }
  • Sets the generator to use the specified point offset.

    Declaration

    Swift

    @discardableResult
    public func withPointOffset(_ pointOffset: CGFloat) -> EFQRCodeGenerator

    Parameters

    pointOffset

    Foreground point offset.

    Return Value

    self, allowing chaining.

  • If false (default), area of watermark where alpha is 0 will be transparent.

    Declaration

    Swift

    public var isWatermarkOpaque: Bool { get set }
  • Set generator to treat watermark image as opaque (or not).

    Declaration

    Swift

    @discardableResult
    public func withOpaqueWatermark(_ isWatermarkOpaque: Bool = true) -> EFQRCodeGenerator

    Parameters

    isWatermarkOpaque

    Should ignore alpha channel or not, defaults to true.

    Return Value

    self, allowing chaining.

  • Set generator to treat watermark image as transparent (or not).

    Declaration

    Swift

    @discardableResult
    public func withTransparentWatermark(_ isTransparent: Bool = true) -> EFQRCodeGenerator

    Parameters

    isTransparent

    Should use alpha channel or not, defaults to true.

    Return Value

    self, allowing chaining.

  • Style of foreground code points, defaults to EFPointStyle.square.

    Declaration

    Swift

    public var pointStyle: EFPointStyle { get set }
  • Set generator to use the specified foreground point style.

    Declaration

    Swift

    @discardableResult
    public func withPointStyle(_ pointStyle: EFPointStyle) -> EFQRCodeGenerator

    Parameters

    pointStyle

    Style of foreground code points.

    Return Value

    self, allowing chaining.

  • If true (default), points for timing pattern will be squares.

    Declaration

    Swift

    public var isTimingPointStatic: Bool { get set }
  • Set generator to use un-styled points for timing pattern (or not).

    Declaration

    Swift

    @discardableResult
    public func withStaticTimingPoint(_ isStatic: Bool = true) -> EFQRCodeGenerator

    Parameters

    isStatic

    Wether or not to use square shape for timing pattern points, defaults to true.

    Return Value

    self, allowing chaining.

  • Set generator to use styled points for timing pattern (or not).

    Declaration

    Swift

    @discardableResult
    public func withStyledTimingPoint(_ ignoreTiming: Bool = true) -> EFQRCodeGenerator

    Parameters

    ignoreTiming

    Wether or not to use current pointStyle for timing pattern points, defaults to true.

    Return Value

    self, allowing chaining.

Cache

  • Clears the cache.

    Note

    You do not need to call this except for reducing memory usage.

    Declaration

    Swift

    public func clearCache()

Init

  • Initialize a QR code generator to generate a QR code of specified of size for some content with appropriate encoding.

    Declaration

    Swift

    public init(
        content: String, encoding: String.Encoding = .utf8,
        size: EFIntSize = EFIntSize(width: 256, height: 256)
    )

    Parameters

    content

    Information to convey in the generated QR code.

    encoding

    Text encoding for generating data from content.

    size

    The width and height of the generated QR code.

  • Fetches the final QR code image.

    Declaration

    Swift

    public func generate() -> CGImage?

    Return Value

    the generated QR code, or nil if failed.

Recommended Magnification

  • Calculates and returns the magnification such that multiplied to intrinsic size >= the given size.

    Declaration

    Swift

    public func minMagnification(greaterThanOrEqualTo size: CGFloat) -> Int?

    Parameters

    size

    Desired final size of generated QR code.

    Return Value

    The recommended value to set as a side of magnification.

  • Calculates and returns the magnification such that multiplied to intrinsic size <= the given size.

    Declaration

    Swift

    public func maxMagnification(lessThanOrEqualTo size: CGFloat) -> Int?

    Parameters

    size

    Desired final size of generated QR code.

    Return Value

    The recommended value to set as a side of magnification.