You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
//
|
|
// VisibilityInputView.swift
|
|
// elpha-ios
|
|
//
|
|
// Created by Dwayne Harris on 11/17/18.
|
|
// Copyright © 2018 Elpha. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
protocol VisibilityInputViewDelegate: class {
|
|
func visibilitySelected(_ sender: Any, visibility: StatusVisibility)
|
|
}
|
|
|
|
class VisibilityInputView: UIView {
|
|
@IBOutlet var contentView: UIView!
|
|
@IBOutlet var visibilityPickerView: UIPickerView!
|
|
|
|
public weak var delegate: VisibilityInputViewDelegate?
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
setup()
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
setup()
|
|
}
|
|
|
|
private func setup() {
|
|
Bundle.main.loadNibNamed("VisibilityInputView", owner: self, options: nil)
|
|
addSubview(contentView)
|
|
contentView.frame = self.bounds
|
|
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
|
visibilityPickerView.delegate = self
|
|
visibilityPickerView.dataSource = self
|
|
}
|
|
}
|
|
|
|
extension VisibilityInputView: UIPickerViewDelegate, UIPickerViewDataSource {
|
|
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
|
return 1
|
|
}
|
|
|
|
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
|
return StatusVisibility.allCases.count
|
|
}
|
|
|
|
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
|
return StatusVisibility.allCases[row].rawValue.capitalized
|
|
}
|
|
|
|
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
|
delegate?.visibilitySelected(self, visibility: StatusVisibility.allCases[row])
|
|
}
|
|
}
|