thiagoperes / IDMPhotoBrowser

Photo Browser / Viewer inspired by Facebook's and Tweetbot's with ARC support, swipe-to-dismiss, image progress and more
MIT License
2.71k stars 642 forks source link

Customize bottom toolbar #256

Open malcommac opened 7 years ago

malcommac commented 7 years ago

Is possible to customize the bottom toolbar with custom elements?

malcommac commented 7 years ago

Just for reference the only workaround I've found right now is to create a subclass and override the updateToolbar() function (cannot call super to avoid loops).

Following example add a custom share button.

class PhotoBrowser: IDMPhotoBrowser {

    public lazy var items: [UIBarButtonItem] = {
        let flexible_space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
        let share_button = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareGallery))
        return [flexible_space,share_button]
    }()

    public var bottomToolbar: UIToolbar {
        get {
            let toolbar = self.value(forKey: "_toolbar") as! UIToolbar
            toolbar.tintColor = UIColor.white
            return toolbar
        }
    }

    public func updateToolbar() {
        self.bottomToolbar.setItems(items, animated: false)
    }

    public func shareGallery() {
        // something...
    }

}