adds lights UI
This commit is contained in:
@@ -20,6 +20,12 @@ class SwitchesViewController: UIViewController,
|
||||
{
|
||||
weak var delegate: SwitchesViewControllerDelegate?
|
||||
|
||||
public var cellHeightScale: Double = 1.0
|
||||
public var actionCellLayout: ActionCellLayout = .vertical
|
||||
public var labelText: String = "switches" {
|
||||
didSet { _label.text = labelText }
|
||||
}
|
||||
|
||||
fileprivate var _collectionView: UICollectionView = UICollectionView(frame: CGRect.zero,
|
||||
collectionViewLayout: UICollectionViewFlowLayout())
|
||||
|
||||
@@ -27,6 +33,8 @@ class SwitchesViewController: UIViewController,
|
||||
|
||||
fileprivate var _currentDevicesHash: Int = 0
|
||||
|
||||
fileprivate let _label = UILabel(frame: .zero)
|
||||
|
||||
static fileprivate let collectionViewDeviceSwitchCellReuseIdentifier = "DeviceSwitchReuseID"
|
||||
static fileprivate let collectionViewActionCellReuseIdentifier = "ActionCellReuseID"
|
||||
static fileprivate let collectionViewCellsSpacing: CGFloat = 5.0
|
||||
@@ -52,6 +60,12 @@ class SwitchesViewController: UIViewController,
|
||||
static let count: Int = { return ActionCell.allCases.count }()
|
||||
}
|
||||
|
||||
public enum ActionCellLayout
|
||||
{
|
||||
case horizontal
|
||||
case vertical
|
||||
}
|
||||
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)
|
||||
{
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
@@ -84,6 +98,11 @@ class SwitchesViewController: UIViewController,
|
||||
{
|
||||
super.viewDidLoad()
|
||||
|
||||
_label.text = labelText
|
||||
_label.font = UIFont(name: "Orbitron-Medium", size: 14.0)
|
||||
_label.textColor = .white.withAlphaComponent(0.8)
|
||||
self.view.addSubview(_label)
|
||||
|
||||
let deviceCellReuseID = SwitchesViewController.collectionViewDeviceSwitchCellReuseIdentifier
|
||||
let actionCellReuseID = SwitchesViewController.collectionViewActionCellReuseIdentifier
|
||||
let layout = _collectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
@@ -106,7 +125,23 @@ class SwitchesViewController: UIViewController,
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
let bounds = self.view.bounds
|
||||
_collectionView.frame = bounds
|
||||
|
||||
let labelSpacing = 8.0
|
||||
let labelSize = _label.sizeThatFits(bounds.size)
|
||||
_label.frame = CGRect(
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
width: labelSize.width,
|
||||
height: labelSize.height
|
||||
)
|
||||
|
||||
_collectionView.frame = CGRect(
|
||||
x: 0.0,
|
||||
y: _label.frame.maxY + labelSpacing,
|
||||
width: bounds.width,
|
||||
height: bounds.height - _label.frame.height - labelSpacing
|
||||
)
|
||||
|
||||
_collectionView.collectionViewLayout.invalidateLayout()
|
||||
}
|
||||
|
||||
@@ -196,9 +231,16 @@ class SwitchesViewController: UIViewController,
|
||||
|
||||
let dimensions = floor((collectionView.bounds.size.width / cellsPerRow) - ((spacing * (cellsPerRow - 1.0)) / cellsPerRow))
|
||||
if (indexPath.section == SwitchesViewController.actionCellsSectionIdentifier) {
|
||||
return CGSize(width: collectionView.bounds.size.width, height: rint(dimensions / 1.5))
|
||||
let bounds = collectionView.bounds
|
||||
let height = rint(dimensions / 1.5) * cellHeightScale
|
||||
switch actionCellLayout {
|
||||
case .horizontal:
|
||||
return CGSize(width: (bounds.width - spacing) / 2.0, height: height)
|
||||
case .vertical:
|
||||
return CGSize(width: bounds.size.width, height: height)
|
||||
}
|
||||
} else {
|
||||
return CGSize(width: dimensions, height: dimensions)
|
||||
return CGSize(width: dimensions, height: dimensions * cellHeightScale)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user