Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom cancel button #42

Closed
RealBug opened this issue Nov 29, 2016 · 2 comments
Closed

Custom cancel button #42

RealBug opened this issue Nov 29, 2016 · 2 comments

Comments

@RealBug
Copy link

RealBug commented Nov 29, 2016

Your component is great!

I just regret that we can't customize the cancel button.
In the example of spotify, if you want to put a button with title in black (white by default, you can not modify it) and add margins to the left and right), how can you do it?

Thank you in advance

@RealBug RealBug changed the title Your component is great! I just regret that we can not customize the cancel button. In the example of spotify, if you want to put a button with title in black (white by default, you can not modify it) and add margins to the left and right), how can you do it? thank you in advance Custom cancel button Nov 29, 2016
@m-revetria
Copy link
Member

Hi @RealBug, thanks for your contribution!

Right you can use a custom cancelView in a subclass of XLActionController by creating it in viewDidLoad before calling super. Take a look to the next code snippet:

open class CustomActionController: ActionController<CustomCell, ActionData, CustomHeaderView, SpotifyHeaderData, UICollectionReusableView, Void> {
   
    public override init(nibName nibNameOrNil: String? = nil, bundle nibBundleOrNil: Bundle? = nil) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

        settings.cancelView.showCancel = true
        settings.cancelView.backgroundColor = .lightGray

        // Add all needed settings
    }

    open override func viewDidLoad() {
        cancelView = {
            let cancelView = UIView(frame: CGRect(x: 0, y: 0, width: view.bounds.size.width, height: settings.cancelView.height))
            cancelView.backgroundColor = settings.cancelView.backgroundColor

            let button = UIButton()
            button.backgroundColor = .white
            button.setTitle("Cancel", for: .normal)
            button.setTitleColor(.black, for: .normal)
            button.translatesAutoresizingMaskIntoConstraints = false

            cancelView.addSubview(button)
            cancelView.addConstraints(
                NSLayoutConstraint.constraints(withVisualFormat: "H:|-20-[button]-20-|", options: [], metrics: nil, views: ["button": button]) +
                NSLayoutConstraint.constraints(withVisualFormat: "V:|-5-[button]-5-|", options: [], metrics: nil, views: ["button": button])
            )

            return cancelView
        }()

        super.viewDidLoad()
    }

}

We are planning to add support for a CancelViewSpec in a future version, which will allow developers to completely customize the cancelView's style similarly to how the header is defined. But for now you can do something similar to the code shown above.

@RealBug
Copy link
Author

RealBug commented Nov 29, 2016

Awesome, thank you for your great work !

@RealBug RealBug closed this as completed Nov 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants