Beginning work on device cells

This commit is contained in:
Charles Magahern
2015-12-31 15:41:32 -08:00
parent 5b535f5720
commit df0f72af23
7 changed files with 368 additions and 26 deletions
@@ -0,0 +1,105 @@
//
// SwitchIndicatorView.swift
// XIONControlPanel
//
// Created by Charles Magahern on 12/31/15.
// Copyright © 2015 XION. All rights reserved.
//
import UIKit
class SwitchIndicatorView: UIView {
private var _status: Bool = false
private var _foregroundColor: UIColor = UIColor.whiteColor()
private var _outerCircleLayer: CAShapeLayer = CAShapeLayer()
private var _offSymbolLayer: CAShapeLayer = CAShapeLayer()
private var _onSymbolLayer: CAShapeLayer = CAShapeLayer()
static private var lineWidth: CGFloat = 2.0
override init(frame: CGRect)
{
super.init(frame: frame)
_outerCircleLayer.fillColor = UIColor.clearColor().CGColor
_outerCircleLayer.lineWidth = SwitchIndicatorView.lineWidth
_offSymbolLayer.fillColor = UIColor.clearColor().CGColor
_offSymbolLayer.lineWidth = SwitchIndicatorView.lineWidth
self.layer.addSublayer(_outerCircleLayer)
self.layer.addSublayer(_offSymbolLayer)
self.layer.addSublayer(_onSymbolLayer)
self.status = false
self.foregroundColor = UIColor.whiteColor()
}
required init?(coder aDecoder: NSCoder)
{
fatalError("unsupported")
}
override func layoutSubviews()
{
super.layoutSubviews()
let bounds = self.bounds
let lineWidth = SwitchIndicatorView.lineWidth
_outerCircleLayer.frame = bounds
_offSymbolLayer.frame = bounds
_onSymbolLayer.frame = bounds
_outerCircleLayer.path = CGPathCreateWithEllipseInRect(bounds, nil)
let innerSize = CGSize(width: rint(bounds.size.width / 2.0), height: rint(bounds.size.height / 2.0))
let innerBounds = CGRect(
x: rint(bounds.size.width / 2.0 - innerSize.width / 2.0),
y: rint(bounds.size.height / 2.0 - innerSize.height / 2.0),
width: innerSize.width,
height: innerSize.height
)
_offSymbolLayer.path = CGPathCreateWithEllipseInRect(innerBounds, nil)
let onSymbolSize = CGSize(width: lineWidth, height: innerSize.height)
let onSymbolRect = CGRect(
x: rint(bounds.size.width / 2.0 - onSymbolSize.width / 2.0),
y: rint(bounds.size.height / 2.0 - onSymbolSize.height / 2.0),
width: onSymbolSize.width,
height: onSymbolSize.height
)
_onSymbolLayer.path = CGPathCreateWithRect(onSymbolRect, nil)
}
// MARK: API
var status: Bool {
get
{
return _status
}
set(status)
{
_status = status
_offSymbolLayer.hidden = _status
_onSymbolLayer.hidden = !_status
}
}
var foregroundColor: UIColor {
get
{
return _foregroundColor
}
set(color)
{
_foregroundColor = color
_outerCircleLayer.strokeColor = _foregroundColor.CGColor
_offSymbolLayer.strokeColor = _foregroundColor.CGColor
_onSymbolLayer.fillColor = _foregroundColor.CGColor
}
}
}
@@ -0,0 +1,105 @@
//
// WemoDeviceCellView.swift
// XIONControlPanel
//
// Created by Charles Magahern on 12/31/15.
// Copyright © 2015 XION. All rights reserved.
//
import UIKit
class WemoDeviceCellView: UICollectionViewCell {
private var _device: WemoDevice?
private var _ordinal: Int = 0
private var _nameLabel: UILabel = UILabel()
private var _ordinalLabel: UILabel = UILabel()
private var _indicator: SwitchIndicatorView = SwitchIndicatorView()
override init(frame: CGRect)
{
super.init(frame: frame)
let annotationsColor = UIColor.darkGrayColor()
self.backgroundColor = UIColor(white: 0.2, alpha: 1.0)
_nameLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
_nameLabel.numberOfLines = 3
_nameLabel.textColor = UIColor.whiteColor()
_nameLabel.text = "beatmania IIDX".uppercaseString
self.addSubview(_nameLabel)
_ordinalLabel.font = UIFont(name: "Orbitron-Medium", size: 21.0)
_ordinalLabel.textColor = annotationsColor
_ordinalLabel.text = "00"
self.addSubview(_ordinalLabel)
_indicator.foregroundColor = annotationsColor
self.addSubview(_indicator)
}
required init?(coder aDecoder: NSCoder)
{
fatalError("unsupported")
}
// MARK: Overrides
override func layoutSubviews()
{
super.layoutSubviews()
let bounds = self.bounds
let padding: CGFloat = 10.0
_indicator.frame = CGRect(
x: padding,
y: padding,
width: 20.0,
height: 20.0
)
let nameLabelSize = _nameLabel.sizeThatFits(CGSize(width: bounds.size.width - padding * 2.0, height: bounds.size.height - padding))
_nameLabel.frame = CGRect(
x: padding,
y: bounds.size.height - nameLabelSize.height - padding,
width: nameLabelSize.width,
height: nameLabelSize.height
)
let ordinalLabelSize = _ordinalLabel.sizeThatFits(bounds.size)
_ordinalLabel.frame = CGRect(
x: bounds.size.width - ordinalLabelSize.width - padding,
y: padding,
width: ordinalLabelSize.width,
height: ordinalLabelSize.height
)
}
// MARK: API
var device: WemoDevice? {
get
{
return _device
}
set(device)
{
_device = device
_nameLabel.text = _device?.name
}
}
var ordinal: Int {
get
{
return _ordinal
}
set(ordinal)
{
_ordinal = ordinal
_ordinalLabel.text = String(format: "%.2d", _ordinal)
}
}
}