Conversion to Swift3

This commit is contained in:
Charles Magahern
2017-05-13 00:40:03 -07:00
parent 687b45c73a
commit 091af0844a
16 changed files with 353 additions and 325 deletions

View File

@@ -10,25 +10,25 @@ import UIKit
class ConnectionStatusView: UIView
{
private var _connectivityStatus: ConnectionStatus = .Disconnected
private var _japaneseLabel: UILabel = UILabel()
private var _englishLabel: UILabel = UILabel()
fileprivate var _connectivityStatus: ConnectionStatus = .disconnected
fileprivate var _japaneseLabel: UILabel = UILabel()
fileprivate var _englishLabel: UILabel = UILabel()
static private let labelsVMargin: CGFloat = 5.0
static fileprivate let labelsVMargin: CGFloat = 5.0
override init(frame: CGRect)
{
super.init(frame: frame)
_japaneseLabel.font = UIFont(name: "Orbitron-Medium", size: 24.0)
_japaneseLabel.textColor = UIColor.whiteColor()
_japaneseLabel.textColor = UIColor.white
self.addSubview(_japaneseLabel)
_englishLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
_englishLabel.textColor = UIColor.whiteColor()
_englishLabel.textColor = UIColor.white
self.addSubview(_englishLabel)
self.connectivityStatus = .Disconnected
self.connectivityStatus = .disconnected
}
required init?(coder aDecoder: NSCoder)
@@ -38,7 +38,7 @@ class ConnectionStatusView: UIView
// MARK: Overrides
override func sizeThatFits(size: CGSize) -> CGSize
override func sizeThatFits(_ size: CGSize) -> CGSize
{
let labelsVMargin = ConnectionStatusView.labelsVMargin
let jpLabelSize = _japaneseLabel.sizeThatFits(size)
@@ -67,7 +67,7 @@ class ConnectionStatusView: UIView
_englishLabel.frame = CGRect(
x: rint(bounds.size.width / 2.0 - enLabelSize.width / 2.0),
y: CGRectGetMaxY(_japaneseLabel.frame) + labelsVMargin,
y: _japaneseLabel.frame.maxY + labelsVMargin,
width: enLabelSize.width,
height: enLabelSize.height
)
@@ -87,30 +87,30 @@ class ConnectionStatusView: UIView
_connectivityStatus = newStatus
switch (_connectivityStatus) {
case .Disconnected:
case .disconnected:
_japaneseLabel.text = "非直結"
_japaneseLabel.textColor = UIColor.redColor()
_japaneseLabel.textColor = UIColor.red
_englishLabel.text = "offline"
_englishLabel.textColor = UIColor.redColor()
case .Connecting:
_englishLabel.textColor = UIColor.red
case .connecting:
_japaneseLabel.text = "接続中"
_japaneseLabel.textColor = UIColor.yellowColor()
_japaneseLabel.textColor = UIColor.yellow
_englishLabel.text = "connecting..."
_englishLabel.textColor = UIColor.yellowColor()
case .Connected:
_englishLabel.textColor = UIColor.yellow
case .connected:
_japaneseLabel.text = "直結"
_japaneseLabel.textColor = UIColor.greenColor()
_japaneseLabel.textColor = UIColor.green
_englishLabel.text = "online"
_englishLabel.textColor = UIColor.greenColor()
case .Error:
_englishLabel.textColor = UIColor.green
case .error:
_japaneseLabel.text = "過失"
_japaneseLabel.textColor = UIColor.redColor()
_japaneseLabel.textColor = UIColor.red
_englishLabel.text = "error"
_englishLabel.textColor = UIColor.redColor()
_englishLabel.textColor = UIColor.red
}
self.setNeedsLayout()

View File

@@ -15,24 +15,24 @@ class HeaderView: UIView
var xionLogoView: XIONLogoView = XIONLogoView()
var connectionStatusView: ConnectionStatusView = ConnectionStatusView()
private var _xionTitleLabel: UILabel = UILabel()
private var _xionJapaneseLabel: UILabel = UILabel()
fileprivate var _xionTitleLabel: UILabel = UILabel()
fileprivate var _xionJapaneseLabel: UILabel = UILabel()
override init(frame: CGRect)
{
super.init(frame: frame)
self.backgroundColor = UIColor.blackColor()
self.backgroundColor = UIColor.black
self.addSubview(self.xionLogoView)
_xionTitleLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
_xionTitleLabel.text = "XION arcade system control panel"
_xionTitleLabel.textColor = UIColor.whiteColor()
_xionTitleLabel.textColor = UIColor.white
self.addSubview(_xionTitleLabel)
_xionJapaneseLabel.font = UIFont(name: "Orbitron-Medium", size: 12.0)
_xionJapaneseLabel.text = "ザイーオンゲームセンターのシステム制御プログラム"
_xionJapaneseLabel.textColor = UIColor.whiteColor()
_xionJapaneseLabel.textColor = UIColor.white
self.addSubview(_xionJapaneseLabel)
self.addSubview(self.connectionStatusView)
@@ -59,12 +59,12 @@ class HeaderView: UIView
)
self.xionLogoView.frame = logoFrame
if (self.traitCollection.horizontalSizeClass == .Compact) {
_xionTitleLabel.hidden = true
_xionJapaneseLabel.hidden = true
if (self.traitCollection.horizontalSizeClass == .compact) {
_xionTitleLabel.isHidden = true
_xionJapaneseLabel.isHidden = true
} else {
_xionTitleLabel.hidden = false
_xionJapaneseLabel.hidden = false
_xionTitleLabel.isHidden = false
_xionJapaneseLabel.isHidden = false
let titleJPVerticalMargin: CGFloat = 5.0
let titleLabelSize = _xionTitleLabel.sizeThatFits(bounds.size)
@@ -72,7 +72,7 @@ class HeaderView: UIView
let totalLabelsHeight = titleLabelSize.height + titleJPVerticalMargin + jpLabelSize.height
let titleFrame = CGRect(
x: CGRectGetMaxX(logoFrame) + hpadding * 2.0,
x: logoFrame.maxX + hpadding * 2.0,
y: rint(bounds.size.height / 2.0 - totalLabelsHeight / 2.0),
width: titleLabelSize.width,
height: titleLabelSize.height
@@ -81,7 +81,7 @@ class HeaderView: UIView
let jpTitleFrame = CGRect(
x: titleFrame.origin.x,
y: CGRectGetMaxY(titleFrame) + titleJPVerticalMargin,
y: titleFrame.maxY + titleJPVerticalMargin,
width: jpLabelSize.width,
height: jpLabelSize.height + 2.0
)

View File

@@ -10,22 +10,22 @@ 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()
fileprivate var _status: Bool = false
fileprivate var _foregroundColor: UIColor = UIColor.white
fileprivate var _outerCircleLayer: CAShapeLayer = CAShapeLayer()
fileprivate var _offSymbolLayer: CAShapeLayer = CAShapeLayer()
fileprivate var _onSymbolLayer: CAShapeLayer = CAShapeLayer()
static private var lineWidth: CGFloat = 2.0
static fileprivate var lineWidth: CGFloat = 2.0
override init(frame: CGRect)
{
super.init(frame: frame)
_outerCircleLayer.fillColor = UIColor.clearColor().CGColor
_outerCircleLayer.fillColor = UIColor.clear.cgColor
_outerCircleLayer.lineWidth = SwitchIndicatorView.lineWidth
_offSymbolLayer.fillColor = UIColor.clearColor().CGColor
_offSymbolLayer.fillColor = UIColor.clear.cgColor
_offSymbolLayer.lineWidth = SwitchIndicatorView.lineWidth
self.layer.addSublayer(_outerCircleLayer)
@@ -33,7 +33,7 @@ class SwitchIndicatorView: UIView
self.layer.addSublayer(_onSymbolLayer)
self.status = false
self.foregroundColor = UIColor.whiteColor()
self.foregroundColor = UIColor.white
}
required init?(coder aDecoder: NSCoder)
@@ -52,7 +52,7 @@ class SwitchIndicatorView: UIView
_offSymbolLayer.frame = bounds
_onSymbolLayer.frame = bounds
_outerCircleLayer.path = CGPathCreateWithEllipseInRect(bounds, nil)
_outerCircleLayer.path = CGPath(ellipseIn: bounds, transform: nil)
let innerSize = CGSize(width: rint(bounds.size.width / 2.0), height: rint(bounds.size.height / 2.0))
let innerBounds = CGRect(
@@ -61,7 +61,7 @@ class SwitchIndicatorView: UIView
width: innerSize.width,
height: innerSize.height
)
_offSymbolLayer.path = CGPathCreateWithEllipseInRect(innerBounds, nil)
_offSymbolLayer.path = CGPath(ellipseIn: innerBounds, transform: nil)
let onSymbolSize = CGSize(width: lineWidth, height: innerSize.height)
let onSymbolRect = CGRect(
@@ -70,7 +70,7 @@ class SwitchIndicatorView: UIView
width: onSymbolSize.width,
height: onSymbolSize.height
)
_onSymbolLayer.path = CGPathCreateWithRect(onSymbolRect, nil)
_onSymbolLayer.path = CGPath(rect: onSymbolRect, transform: nil)
}
// MARK: API
@@ -85,8 +85,8 @@ class SwitchIndicatorView: UIView
set(status)
{
_status = status
_offSymbolLayer.hidden = _status
_onSymbolLayer.hidden = !_status
_offSymbolLayer.isHidden = _status
_onSymbolLayer.isHidden = !_status
}
}
@@ -100,9 +100,9 @@ class SwitchIndicatorView: UIView
set(color)
{
_foregroundColor = color
_outerCircleLayer.strokeColor = _foregroundColor.CGColor
_offSymbolLayer.strokeColor = _foregroundColor.CGColor
_onSymbolLayer.fillColor = _foregroundColor.CGColor
_outerCircleLayer.strokeColor = _foregroundColor.cgColor
_offSymbolLayer.strokeColor = _foregroundColor.cgColor
_onSymbolLayer.fillColor = _foregroundColor.cgColor
}
}
}

View File

@@ -8,12 +8,12 @@
import UIKit
public class WemoCellView: UICollectionViewCell
open class WemoCellView: UICollectionViewCell
{
private var _selectionOverlayView: UIView = UIView()
fileprivate var _selectionOverlayView: UIView = UIView()
static private var disabledBackgroundColor = UIColor(white: 0.2, alpha: 1.0)
static private var enabledBackgroundColor = UIColor(red: 0.0, green: 0.8, blue: 0.0, alpha: 1.0)
static fileprivate var disabledBackgroundColor = UIColor(white: 0.2, alpha: 1.0)
static fileprivate var enabledBackgroundColor = UIColor(red: 0.0, green: 0.8, blue: 0.0, alpha: 1.0)
override init(frame: CGRect)
{
@@ -21,7 +21,7 @@ public class WemoCellView: UICollectionViewCell
self.contentView.backgroundColor = WemoCellView.disabledBackgroundColor
_selectionOverlayView.backgroundColor = UIColor.clearColor()
_selectionOverlayView.backgroundColor = UIColor.clear
self.contentView.addSubview(_selectionOverlayView)
}
@@ -32,7 +32,7 @@ public class WemoCellView: UICollectionViewCell
// MARK: Overrides
override public func layoutSubviews()
override open func layoutSubviews()
{
super.layoutSubviews()
@@ -40,29 +40,30 @@ public class WemoCellView: UICollectionViewCell
_selectionOverlayView.frame = bounds
}
override public var highlighted: Bool {
override open var isHighlighted: Bool {
didSet
{
if (self.highlighted) {
if (self.isHighlighted) {
_selectionOverlayView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
} else {
let animOptions = UIViewAnimationOptions([.AllowUserInteraction])
UIView.animateWithDuration(1.0, delay: 0.0, options: animOptions, animations: {
self._selectionOverlayView.backgroundColor = UIColor.clearColor()
let animOptions = UIViewAnimationOptions([.allowUserInteraction])
UIView.animate(withDuration: 1.0, delay: 0.0, options: animOptions, animations: {
self._selectionOverlayView.backgroundColor = UIColor.clear
}, completion: nil)
}
}
}
}
public class WemoDeviceCellView: WemoCellView {
private var _ordinal: Int = 0
private var _nameLabel: UILabel = UILabel()
private var _ordinalLabel: UILabel = UILabel()
private var _indicator: SwitchIndicatorView = SwitchIndicatorView()
open class WemoDeviceCellView: WemoCellView
{
fileprivate var _ordinal: Int = 0
fileprivate var _nameLabel: UILabel = UILabel()
fileprivate var _ordinalLabel: UILabel = UILabel()
fileprivate var _indicator: SwitchIndicatorView = SwitchIndicatorView()
static private var disabledAnnotationsColor = UIColor.darkGrayColor()
static private var enabledAnnotationsColor = UIColor.blackColor()
static fileprivate var disabledAnnotationsColor = UIColor.darkGray
static fileprivate var enabledAnnotationsColor = UIColor.black
override init(frame: CGRect)
{
@@ -72,7 +73,7 @@ public class WemoDeviceCellView: WemoCellView {
_nameLabel.numberOfLines = 3
_nameLabel.allowsDefaultTighteningForTruncation = true
_nameLabel.adjustsFontSizeToFitWidth = true
_nameLabel.textColor = UIColor.whiteColor()
_nameLabel.textColor = UIColor.white
self.contentView.addSubview(_nameLabel)
_ordinalLabel.font = UIFont(name: "Orbitron-Medium", size: 21.0)
@@ -91,7 +92,7 @@ public class WemoDeviceCellView: WemoCellView {
// MARK: Overrides
override public func layoutSubviews()
override open func layoutSubviews()
{
super.layoutSubviews()
@@ -128,7 +129,7 @@ public class WemoDeviceCellView: WemoCellView {
{
didSet
{
_nameLabel.text = self.deviceName.uppercaseString
_nameLabel.text = self.deviceName.uppercased()
self.setNeedsLayout()
}
}
@@ -167,7 +168,8 @@ public class WemoDeviceCellView: WemoCellView {
}
}
public class WemoActionCellView: WemoCellView {
open class WemoActionCellView: WemoCellView
{
var textLabel: UILabel = UILabel()
override init(frame: CGRect)
@@ -175,8 +177,8 @@ public class WemoActionCellView: WemoCellView {
super.init(frame: frame)
self.textLabel.font = UIFont(name: "Orbitron-Medium", size: 21.0)
self.textLabel.textColor = UIColor.whiteColor()
self.textLabel.textAlignment = .Center
self.textLabel.textColor = UIColor.white
self.textLabel.textAlignment = .center
self.addSubview(self.textLabel)
}
@@ -185,7 +187,7 @@ public class WemoActionCellView: WemoCellView {
fatalError("unsupported")
}
override public func layoutSubviews()
override open func layoutSubviews()
{
super.layoutSubviews()
self.textLabel.frame = self.bounds
@@ -196,9 +198,9 @@ public class WemoActionCellView: WemoCellView {
didSet
{
if (enabled) {
self.textLabel.textColor = UIColor.whiteColor()
self.textLabel.textColor = UIColor.white
} else {
self.textLabel.textColor = UIColor.darkGrayColor()
self.textLabel.textColor = UIColor.darkGray
}
}
}

View File

@@ -10,24 +10,24 @@ import UIKit
class XIONLogoView: UIView
{
private var _xionLogoImageView: UIImageView = UIImageView()
private var _logoInnerRingImageView: UIImageView = UIImageView()
private var _logoOuterRingImageView: UIImageView = UIImageView()
fileprivate var _xionLogoImageView: UIImageView = UIImageView()
fileprivate var _logoInnerRingImageView: UIImageView = UIImageView()
fileprivate var _logoOuterRingImageView: UIImageView = UIImageView()
override init(frame: CGRect)
{
super.init(frame: frame)
self.backgroundColor = UIColor.blackColor()
self.backgroundColor = UIColor.black
_xionLogoImageView.image = UIImage(named: "XIONLogoWithRing")
_xionLogoImageView.contentMode = .ScaleAspectFit
_xionLogoImageView.contentMode = .scaleAspectFit
_logoInnerRingImageView.image = UIImage(named: "XIONLogoInnerRing")
_logoInnerRingImageView.contentMode = .ScaleAspectFit
_logoInnerRingImageView.contentMode = .scaleAspectFit
_logoOuterRingImageView.image = UIImage(named: "XIONLogoOuterRing")
_logoOuterRingImageView.contentMode = .ScaleAspectFit
_logoOuterRingImageView.contentMode = .scaleAspectFit
self.addSubview(_logoOuterRingImageView)
self.addSubview(_logoInnerRingImageView)
@@ -55,7 +55,7 @@ class XIONLogoView: UIView
{
self.stopAnimating()
let duration: NSTimeInterval = 20.0
let duration: TimeInterval = 20.0
let clockwiseAnim = CABasicAnimation(keyPath: "transform.rotation")
clockwiseAnim.fromValue = 0.0
@@ -69,8 +69,8 @@ class XIONLogoView: UIView
counterClockwiseAnim.duration = duration
counterClockwiseAnim.repeatCount = Float.infinity
_logoInnerRingImageView.layer.addAnimation(clockwiseAnim, forKey: "LogoClockwiseAnimation")
_logoOuterRingImageView.layer.addAnimation(counterClockwiseAnim, forKey: "LogoCounterclockwiseAnimation")
_logoInnerRingImageView.layer.add(clockwiseAnim, forKey: "LogoClockwiseAnimation")
_logoOuterRingImageView.layer.add(counterClockwiseAnim, forKey: "LogoCounterclockwiseAnimation")
}
func stopAnimating()