Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Make the buttons center-aligned #11

Closed
Sweeper777 opened this issue Feb 16, 2017 · 12 comments
Closed

Make the buttons center-aligned #11

Sweeper777 opened this issue Feb 16, 2017 · 12 comments

Comments

@Sweeper777
Copy link

Is there a way to make the buttons center aligned? Right now, all the buttons are on the left (left aligned). People have to move their hands a lot to tap on them on a really wide screen.

@ruddfawcett
Copy link
Owner

Can you post a screenshot?

@Sweeper777
Copy link
Author

I will try to photoshop my desired result

@ruddfawcett
Copy link
Owner

Do you mean something like this?

iphone 7

@Sweeper777
Copy link
Author

Yes, exactly that!

@ruddfawcett
Copy link
Owner

You can accomplish this by subclassing the toolbar and redrawing the layout (just calculate width of buttons and then plop in center or use auto layout).

@Sweeper777
Copy link
Author

Which method should I override? I can't find anything related to collection views in RFKeyboardToolbar. Did you not expose it?

@ruddfawcett
Copy link
Owner

ruddfawcett commented Feb 19, 2017

Check out addButtons.

@Sweeper777
Copy link
Author

Sweeper777 commented Feb 19, 2017

It does not seem to be visible in subclasses. Is it private? It has a - in front of it. That means it's private right?

@Sweeper777
Copy link
Author

I overrode it like this:

override func addButtons() {
    let buttons = self.buttons.map { $0 as! RFToolbarButton }
    let totalWidth = buttons.reduce(0) { $0 + $1.width + 8 } - 8
    if totalWidth > scrollView.width {
        super.addButtons()
        return
    }
    var originX = (scrollView.width - totalWidth) / 2
    for button in buttons {
        button.x = originX
        button.y = 0
        originX += button.width + 8
        scrollView.addSubview(button)
    }
}

But the overridden method does not seem to get called. The buttons' positions stay the same as before.

@ruddfawcett
Copy link
Owner

And you're using your subclass?

@Sweeper777
Copy link
Author

Yes of course! I stepped through the code and found that only the super class's addButton is called.

@ruddfawcett
Copy link
Owner

@Sweeper777 closing due to inactivity. Please reopen if you are still experiencing this issue. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants