// // HeaderView.swift // XIONControlPanel // // Created by Charles Magahern on 12/30/15. // Copyright © 2015 XION. All rights reserved. // import Darwin import Foundation import UIKit class HeaderView: UIView { var xionLogoView: XIONLogoView = XIONLogoView() var connectionStatusView: ConnectionStatusView = ConnectionStatusView() fileprivate var _xionTitleLabel: UILabel = UILabel() fileprivate var _xionJapaneseLabel: UILabel = UILabel() override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = UIColor.black self.addSubview(self.xionLogoView) _xionTitleLabel.font = UIFont(name: "Orbitron-Medium", size: 18.0) _xionTitleLabel.text = "XAIBATSU arcade system control panel" _xionTitleLabel.textColor = UIColor.white self.addSubview(_xionTitleLabel) _xionJapaneseLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0) _xionJapaneseLabel.text = "ザイバツゲームセンターのシステム制御プログラム" _xionJapaneseLabel.textColor = UIColor.white self.addSubview(_xionJapaneseLabel) self.addSubview(self.connectionStatusView) } required init?(coder aDecoder: NSCoder) { fatalError("unsupported") } override func layoutSubviews() { super.layoutSubviews() let bounds = self.bounds let hpadding = CGFloat(10.0) let logoDimensions = rint(bounds.size.height / 1.2) let logoFrame = CGRect( x: hpadding, y: rint(bounds.size.height / 2.0 - logoDimensions / 2.0), width: logoDimensions, height: logoDimensions ) self.xionLogoView.frame = logoFrame if (self.traitCollection.horizontalSizeClass == .compact) { _xionTitleLabel.isHidden = true _xionJapaneseLabel.isHidden = true } else { _xionTitleLabel.isHidden = false _xionJapaneseLabel.isHidden = false let titleJPVerticalMargin: CGFloat = 5.0 let titleLabelSize = _xionTitleLabel.sizeThatFits(bounds.size) let jpLabelSize = _xionJapaneseLabel.sizeThatFits(bounds.size) let totalLabelsHeight = titleLabelSize.height + titleJPVerticalMargin + jpLabelSize.height let titleFrame = CGRect( x: logoFrame.maxX + hpadding * 2.0, y: rint(bounds.size.height / 2.0 - totalLabelsHeight / 2.0), width: titleLabelSize.width, height: titleLabelSize.height ) _xionTitleLabel.frame = titleFrame let jpTitleFrame = CGRect( x: titleFrame.origin.x, y: titleFrame.maxY + titleJPVerticalMargin, width: jpLabelSize.width, height: jpLabelSize.height + 2.0 ) _xionJapaneseLabel.frame = jpTitleFrame } let connectionStatusDimensions = self.connectionStatusView.sizeThatFits(bounds.size) let connectionStatusFrame = CGRect( x: bounds.size.width - connectionStatusDimensions.width - hpadding, y: rint(bounds.size.height / 2.0 - connectionStatusDimensions.height / 2.0), width: connectionStatusDimensions.width, height: connectionStatusDimensions.height ) self.connectionStatusView.frame = connectionStatusFrame } }