[ABANDONED] Mastodon iOS client.
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

  1. //
  2. // VisibilityInputView.swift
  3. // elpha-ios
  4. //
  5. // Created by Dwayne Harris on 11/17/18.
  6. // Copyright © 2018 Elpha. All rights reserved.
  7. //
  8. import UIKit
  9. protocol VisibilityInputViewDelegate: class {
  10. func visibilitySelected(_ sender: Any, visibility: StatusVisibility)
  11. }
  12. class VisibilityInputView: UIView {
  13. @IBOutlet var contentView: UIView!
  14. @IBOutlet var visibilityPickerView: UIPickerView!
  15. public weak var delegate: VisibilityInputViewDelegate?
  16. override init(frame: CGRect) {
  17. super.init(frame: frame)
  18. setup()
  19. }
  20. required init?(coder aDecoder: NSCoder) {
  21. super.init(coder: aDecoder)
  22. setup()
  23. }
  24. private func setup() {
  25. Bundle.main.loadNibNamed("VisibilityInputView", owner: self, options: nil)
  26. addSubview(contentView)
  27. contentView.frame = self.bounds
  28. contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  29. visibilityPickerView.delegate = self
  30. visibilityPickerView.dataSource = self
  31. }
  32. }
  33. extension VisibilityInputView: UIPickerViewDelegate, UIPickerViewDataSource {
  34. func numberOfComponents(in pickerView: UIPickerView) -> Int {
  35. return 1
  36. }
  37. func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
  38. return StatusVisibility.allCases.count
  39. }
  40. func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
  41. return StatusVisibility.allCases[row].rawValue.capitalized
  42. }
  43. func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
  44. delegate?.visibilitySelected(self, visibility: StatusVisibility.allCases[row])
  45. }
  46. }