12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // ToolbarPickerView.swift
- // Learn Genie
- //
- // Created by Suraj Kumar Mandal on 17/09/21.
- //
- import Foundation
- import UIKit
- protocol ToolbarPickerViewDelegate: AnyObject {
- func didTapDone()
- func didTapCancel()
- }
- class ToolbarPickerView: UIPickerView {
- public private(set) var toolbar: UIToolbar?
- public weak var toolbarDelegate: ToolbarPickerViewDelegate?
- override init(frame: CGRect) {
- super.init(frame: frame)
- self.commonInit()
- }
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- self.commonInit()
- }
- private func commonInit() {
- let toolBar = UIToolbar()
- toolBar.barStyle = UIBarStyle.default
- //toolBar.isTranslucent = true
- //toolBar.tintColor = .black
- toolBar.sizeToFit()
- let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(self.doneTapped))
- let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
- let cancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(self.cancelTapped))
- toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
- toolBar.isUserInteractionEnabled = true
- self.toolbar = toolBar
- }
- @objc func doneTapped() {
- self.toolbarDelegate?.didTapDone()
- }
- @objc func cancelTapped() {
- self.toolbarDelegate?.didTapCancel()
- }
- }
|