uias / Tabman

™️ A powerful paging view controller with interactive indicator bars
https://uias.github.io/Tabman
MIT License
2.86k stars 237 forks source link

How change color when button change state ? #486

Closed tsomaev closed 4 years ago

tsomaev commented 4 years ago

This my code for bar configure, but when I tapped button, color not change. What am I doing wrong ?

   func topBarConfigure() {
        let bar = TMBar.ButtonBar()
        bar.indicator.isHidden = true
        bar.layout.contentInset = UIEdgeInsets(top: 10, left: 16.0, bottom: 0, right: 16.0)

        bar.buttons.customize { button in
            button.layer.cornerRadius = 4
            button.selectedTintColor = .white
            button.layer.masksToBounds  = true
            button.contentInset = UIEdgeInsets(top: 12, left: 16.0, bottom: 12, right: 16.0)
            button.selectedTintColor = .white

            switch button.selectionState {
            case .unselected:
                button.tintColor = .white
                button.backgroundColor = .gray
            case .partial(_):
                button.tintColor = .white
                button.backgroundColor = .mainGreen
            case .selected:
                button.tintColor = .white
                button.backgroundColor = .mainGreen
            }
        }

        addBar(bar, dataSource: self, at: .top)
    }
tsomaev commented 4 years ago

@msaps

msaps commented 4 years ago

@Tawfikk what color property are you wanting to change? Note that customize() is not called when the bar position updates so your switch statement would only ever execute on the initial pass and set the properties according to the state at that time.

Also apologies for the slow response!

tsomaev commented 4 years ago

I want to update color for background color on pager buttons.

Like this

Screenshot 2020-01-12 at 20 02 49
antoinepemeja commented 4 years ago

Hello @msaps and thank you for this library! I have to implement the same logic, the background of TMBarButton has to change when it is selected. You confirm that it's not possible currently, we can just customize the tintColor with selectedTintColor and tintColor? Maybe we can send you a PR to add 2 properties: backgroundColor and selectedBackgroundColor? Or just create our own TMBarButton subclass ? Thank you

Gurungboi commented 4 years ago

Hi @msaps, First of all, thank you for the wonderful library. I do have the same question as above.

Gurungboi commented 4 years ago

Hi @Tawfikk , Did u manage to alcomplish it?

tsomaev commented 4 years ago

@Gurungboi no, this no actually for me. I solved my problem by using other library

Gurungboi commented 4 years ago

@Tawfikk i am still trying but which library are you using?

Gurungboi commented 4 years ago

@Tawfikk I manage to change its state using pageboyViewController.

sugitatestblue commented 3 years ago

WHY don't you write how to resolve it? I waste a lot of time. not need PageboyViewController

I wrote it

class TabPagerButton: Tabman.TMLabelBarButton {
    override func update(for selectionState: TMBarButton.SelectionState) {
        switch selectionState {
        case .selected:
            backgroundColor = .red
        default:
            backgroundColor = .clear
        }

        super.update(for: selectionState)
    }
}

and replaced TMLabelBarButton to TabPagerButton

let barView = TMBarView<TMHorizontalBarLayout, TabPagerButton, TMBarIndicator.None>()