RxSwiftCommunity / RxTheme

Theme management based on Rx
MIT License
382 stars 29 forks source link

Add titleColor Binder for UIButton #9

Closed cozzin closed 6 years ago

cozzin commented 6 years ago

I wanted to apply RxTheme to the UIButton's text, but there was no titleColor Binder. Currently, when we try to change the color of the button's titleLabel, we need to write code like this:

themeService.relay
    .map{ $0 }
    .subscribe { [weak self] theme in
        let textColor = theme.element?.associatedObject.textColor
        self?.button.setTitleColor(textColor, for: .normal)

        let tintColor = theme.element?.associatedObject.tintColor
        self?.button.setTitleColor(tintColor, for: .highlighted)
    }.disposed(by: disposeBag)

So I added titleColor(for state: UIControlState) Binder. This binder makes it easier to write code.

themeService.rx
    .bind({ $0.textColor }, to: button.rx.titleColor(for: .normal))
    .bind({ $0.tintColor }, to: button.rx.titleColor(for: .highlighted))
    .disposed(by: disposeBag)
rxswiftcommunity[bot] commented 6 years ago

Thanks a lot for contributing @cozzin! I've invited you to join the RxSwiftCommunity GitHub organization – no pressure to accept! If you'd like more information on what this means, check out our contributor guidelines and feel free to reach out with any questions.

Generated by :no_entry_sign: dangerJS

wddwycc commented 6 years ago

@cozzin Next time you want to use a binder which RxTheme not supporting yet, You can declare it in your codebase in the first place

cozzin commented 6 years ago

@wddwycc Thank you for your explain ☺️