@buoge
2017-07-27T16:07:36.000000Z
字数 1879
阅读 1601
iOS
let accessoryView = ZZInputAccessoryView.genZZInputAccessoryView()
accessoryView.viewDelegate = self
textField.inputAccessoryView = accessoryView
//
// ZZInputAccessoryView.swift
// zaozuo-ios
//
// Created by wuchuanbo on 2017/7/26.
// Copyright © 2017年 zaozuo. All rights reserved.
//
import Foundation
public protocol ZZInputAccessoryViewDelegate: NSObjectProtocol {
func actionDone()
func actionPrev()
func actionNext()
}
class ZZInputAccessoryView: UIToolbar {
private var prevButton: UIBarButtonItem?
private var nextButton: UIBarButtonItem?
private var doneButton: UIBarButtonItem?
weak var viewDelegate: ZZInputAccessoryViewDelegate?
static func genZZInputAccessoryView() -> ZZInputAccessoryView {
let viewFrame = CGRect(x: 0, y: 0, width: AppWidth, height: 35)
return ZZInputAccessoryView(frame: viewFrame)
}
override init(frame: CGRect) {
super.init(frame: frame)
//toolbar.tintColor = UIColor.blue;
self.backgroundColor = UIColor.gray;
prevButton = UIBarButtonItem(title: "上一步", style: UIBarButtonItemStyle.plain, target: self, action: #selector(ZZInputAccessoryView.actionPrev))
nextButton = UIBarButtonItem(title: "下一步", style: UIBarButtonItemStyle.plain, target: self, action: #selector(ZZInputAccessoryView.actionNext))
let space: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
doneButton = UIBarButtonItem(title: "完成", style: UIBarButtonItemStyle.plain, target: self, action: #selector(ZZInputAccessoryView.actionDone))
if let _prevButton = prevButton,
let _nextButton = nextButton , let _doneButton = doneButton {
self.items = [_prevButton, _nextButton, space, _doneButton]
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
zzerror("init(coder:) has not been implemented")
}
func actionDone() {
viewDelegate?.actionDone()
}
func actionPrev() {
viewDelegate?.actionPrev()
}
func actionNext() {
viewDelegate?.actionNext()
}
}