前端之家收集整理的这篇文章主要介绍了
swift 学习之 ToolbarView,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var toolbar1: UIToolbar!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view,typically from a nib.
configToolbar()
}
func configToolbar() {
let items = [
trashItem,spaceitem,shareItem
]
toolbar1.setItems(items,animated: true)
}
//图标
var trashItem : UIBarButtonItem{
return UIBarButtonItem(barButtonSystemItem: .Trash,target: self,action: "trashclick:")
}
//事件
func trashclick(barItem: UIBarButtonItem ){
//打开不同的也页面
print("\(barItem)您按了删除按钮!")
}
var shareItem : UIBarButtonItem{
return UIBarButtonItem(barButtonSystemItem: .Reply,action: "shareclick:")
}
func shareclick(barItem: UIBarButtonItem ){
print("\(barItem)您按了分享按钮!")
}
var spaceitem : UIBarButtonItem{
return UIBarButtonItem(barButtonSystemItem: .FlexibleSpace,target: nil,action: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}