Connectivity status indicator view

This commit is contained in:
Charles Magahern
2015-12-31 10:55:54 -08:00
parent 29dec42b20
commit 5b535f5720
4 changed files with 126 additions and 17 deletions

View File

@@ -69,12 +69,12 @@ class MainViewController: UIViewController {
override func viewDidAppear(animated: Bool)
{
_headerView.beginAnimating()
_headerView.xionLogoView.beginAnimating()
}
override func viewDidDisappear(animated: Bool)
{
_headerView.stopAnimating()
_headerView.xionLogoView.stopAnimating()
}
override func prefersStatusBarHidden() -> Bool

View File

@@ -0,0 +1,104 @@
//
// ConnectionStatusView.swift
// XIONControlPanel
//
// Created by Charles Magahern on 12/31/15.
// Copyright © 2015 XION. All rights reserved.
//
import UIKit
class ConnectionStatusView: UIView {
private var _connectivityStatus:Bool = false
private var _japaneseLabel: UILabel = UILabel()
private var _englishLabel: UILabel = UILabel()
static private 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()
self.addSubview(_japaneseLabel)
_englishLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
_englishLabel.textColor = UIColor.whiteColor()
self.addSubview(_englishLabel)
self.connectivityStatus = false
}
required init?(coder aDecoder: NSCoder)
{
fatalError("unsupported")
}
// MARK: Overrides
override func sizeThatFits(size: CGSize) -> CGSize
{
let labelsVMargin = ConnectionStatusView.labelsVMargin
let jpLabelSize = _japaneseLabel.sizeThatFits(size)
let enLabelSize = _englishLabel.sizeThatFits(size)
let totalLabelsHeight = jpLabelSize.height + labelsVMargin + enLabelSize.height
let maxLabelsWidth = max(jpLabelSize.width, enLabelSize.width)
return CGSize(width: maxLabelsWidth, height: totalLabelsHeight)
}
override func layoutSubviews()
{
super.layoutSubviews()
let bounds = self.bounds
let labelsVMargin = ConnectionStatusView.labelsVMargin
let jpLabelSize = _japaneseLabel.sizeThatFits(bounds.size)
let enLabelSize = _englishLabel.sizeThatFits(bounds.size)
let totalLabelsHeight = jpLabelSize.height + labelsVMargin + enLabelSize.height
_japaneseLabel.frame = CGRect(
x: rint(bounds.size.width / 2.0 - jpLabelSize.width / 2.0),
y: rint(bounds.size.height / 2.0 - totalLabelsHeight / 2.0),
width: jpLabelSize.width,
height: jpLabelSize.height
)
_englishLabel.frame = CGRect(
x: rint(bounds.size.width / 2.0 - enLabelSize.width / 2.0),
y: CGRectGetMaxY(_japaneseLabel.frame) + labelsVMargin,
width: enLabelSize.width,
height: enLabelSize.height
)
}
// MARK: API
var connectivityStatus: Bool {
get
{
return _connectivityStatus
}
set(newStatus)
{
_connectivityStatus = newStatus
if (_connectivityStatus == true) {
_japaneseLabel.text = "直結"
_japaneseLabel.textColor = UIColor.greenColor()
_englishLabel.text = "online"
_englishLabel.textColor = UIColor.greenColor()
} else {
_japaneseLabel.text = "非直結"
_japaneseLabel.textColor = UIColor.redColor()
_englishLabel.text = "offline"
_englishLabel.textColor = UIColor.redColor()
}
self.setNeedsLayout()
}
}
}

View File

@@ -11,7 +11,9 @@ import Foundation
import UIKit
class HeaderView: UIView {
private var _xionLogoView: XIONLogoView = XIONLogoView()
var xionLogoView: XIONLogoView = XIONLogoView()
var connectionStatusView: ConnectionStatusView = ConnectionStatusView()
private var _xionTitleLabel: UILabel = UILabel()
private var _xionJapaneseLabel: UILabel = UILabel()
@@ -20,7 +22,7 @@ class HeaderView: UIView {
super.init(frame: frame)
self.backgroundColor = UIColor.blackColor()
self.addSubview(_xionLogoView)
self.addSubview(self.xionLogoView)
_xionTitleLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
_xionTitleLabel.text = "XION arcade system control panel"
@@ -31,6 +33,8 @@ class HeaderView: UIView {
_xionJapaneseLabel.text = "ザイーオンゲームセンターのシステム制御プログラム"
_xionJapaneseLabel.textColor = UIColor.whiteColor()
self.addSubview(_xionJapaneseLabel)
self.addSubview(self.connectionStatusView)
}
required init?(coder aDecoder: NSCoder)
@@ -52,7 +56,7 @@ class HeaderView: UIView {
width: logoDimensions,
height: logoDimensions
)
_xionLogoView.frame = logoFrame
self.xionLogoView.frame = logoFrame
let titleJPVerticalMargin: CGFloat = 5.0
let titleLabelSize = _xionTitleLabel.sizeThatFits(bounds.size)
@@ -74,17 +78,14 @@ class HeaderView: UIView {
height: jpLabelSize.height + 2.0
)
_xionJapaneseLabel.frame = jpTitleFrame
}
// MARK: API
func beginAnimating()
{
_xionLogoView.beginAnimating()
}
func stopAnimating()
{
_xionLogoView.stopAnimating()
let connectionStatusDimensions = CGSize(width: rint((1.0 / 8.0) * bounds.size.width), height: bounds.size.height)
let connectionStatusFrame = CGRect(
x: bounds.size.width - connectionStatusDimensions.width,
y: 0.0,
width: connectionStatusDimensions.width,
height: connectionStatusDimensions.height
)
self.connectionStatusView.frame = connectionStatusFrame
}
}