LED_ClockView

public class LED_ClockView : UIView

This class instantiates a bunch of LED Elements into a Digital Clock, to be displayed to cover most of the screen.

  • This is the color we want as the base for our lit segments

    Declaration

    Swift

    var activeSegmentColor: UIColor
  • This is the color for the dead segments

    Declaration

    Swift

    var inactiveSegmentColor: UIColor
  • True, if our numbers will be zero-padded

    Declaration

    Swift

    var zeroPadding: Bool
  • The number of display units between digits.

    Declaration

    Swift

    var separationSpace: Int
  • The hours

    Declaration

    Swift

    var hours: Int { get set }
  • The minutes

    Declaration

    Swift

    var minutes: Int { get set }
  • The seconds

    Declaration

    Swift

    var seconds: Int { get set }
  • This is the number of horizontal lines that appear across the display (simulates the cathode wires in vacuum fluorescent displays).

    Declaration

    Swift

    private let _numberOfLines: Int
  • Whether or not the separators bewteen digit groups are shown.

    Declaration

    Swift

    private var _separatorsOn: Bool
  • Used to pass the calculated paths to the draw method.

    Declaration

    Swift

    private var _allElementGroup: LED_ElementGrouping!
  • Tracks the outline shapes for the segments (inactive)

    Declaration

    Swift

    private var _bottomLayer: CAShapeLayer!
  • Tracks the active (lit) segment shapes.

    Declaration

    Swift

    private var _topLayer: CAGradientLayer!
  • This will contain the LED Display.

    Declaration

    Swift

    private var _displayView: UIView!
  • This will contain a grid that makes the display look like an old-time fluorescent display.

    Declaration

    Swift

    private var _gridImageView: UIImageView!
  • This will set an LED element grouping to display a value, in decimal numbering.

    Declaration

    Swift

    private class func _setDecimalValue(_ inGroup: LED_ElementGrouping, inValue: Int, inZeroFill: Bool)

    Parameters

    inGroup

    The LED element group that comprises one decimal number.

    inValue

    The value to have the group display.

    inZeroFill

    If true, we have leading zeroes displayed.

  • This creates an array of CGPoint, based on a 0,0 origin, that describe a hexagon, on its side (point facing up).

    Declaration

    Swift

    private class func _pointySideUpHexagon(_ inHowBig: CGFloat) -> [CGPoint]

    Parameters

    inHowBig

    The radius, in display units.

    Return Value

    an array of [CGPoint], that can be used to describe a path.

  • This returns a CGMutablePath, describing a pointy side up hexagon.

    Declaration

    Swift

    private class func _getHexPath(_ inHowBig: CGFloat) -> CGMutablePath

    Parameters

    inHowBig

    The radius, in display units.

    Return Value

    A mutable CGPath, describing a pointy side up hexagon.

  • This class generates an overlay image of a faint hex grid that allows us to simulate an old-fashioned fluorescent display.

    Declaration

    Swift

    private func _generateHexOverlayImage(_ fillShape: UIBezierPath) -> UIImage
  • Called when the view needs to have its layout recalculated. Most of the work is done here.

    What we do, is establish the drawing UIBezierPaths for the inactive and active elements, then pass them to the draw method. The draw method then creates CALayers, and displays them, along with a brief animation, simulating a gas flicker, as seen in old-time gas digital displays.

    Declaration

    Swift

    override public func layoutSubviews()
  • This is just here to reduce CC.

    Declaration

    Swift

    func layoutSubviewsPart2()
  • In this drawing routine, we take each of the layers (the bottom, inactive mask layer, and the top, active layer), and render them, with a brief animation that makes a little flare, as seen in the old gas elements. We also render the lit segments with a brightness gradient.

    Declaration

    Swift

    override public func draw(_ rect: CGRect)

    Parameters

    rect

    the rectangle in which to render the display (ignored).