美文网首页
Swift UIBarButtonItem UIToolbar

Swift UIBarButtonItem UIToolbar

作者: 5089dee7e81c | 来源:发表于2018-04-18 10:12 被阅读0次

override func viewDidLoad() {

        super.viewDidLoad()

        let photoItem = UIBarButtonItem(title: "Photo Library", style: .done, target: self, action: #selector(ViewController.showImagePickerForPhotoPicker(_:)))

        photoItem.tintColor = UIColor.white

        let spaceItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

        let cameraItem = UIBarButtonItem(barButtonSystemItem: .camera, target: self, action: #selector(showImagePickerForCamera(_:)))

        cameraItem.tintColor = UIColor.white

        let toolBar = UIToolbar(frame: CGRect.init(x: 0, y: view.frame.size.height-50, width: view.frame.size.width, height: 50))

        toolBar.barTintColor = UIColor.darkGray//背景色

        toolBar.items = [photoItem, spaceItem, cameraItem]

        view.addSubview(toolBar)

    }

    @objc  func showImagePickerForPhotoPicker(_ sender : UIBarButtonItem){

    }

    @objc func showImagePickerForCamera(_ sender: UIBarButtonItem)  {

    }

相关文章

网友评论

      本文标题:Swift UIBarButtonItem UIToolbar

      本文链接:https://www.haomeiwen.com/subject/fsxvkftx.html