Xlpagertabstrip: change selected title color

Created on 25 Nov 2018  路  2Comments  路  Source: xmartlabs/XLPagerTabStrip

Is it possible to set the selected title color / font weight? I currently only see the following styling options:
screen shot 2018-11-25 at 17 49 48

Most helpful comment

Answer for self & others in the future:

self.changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
    oldCell?.label.textColor = UIColor.Ledger.content
    newCell?.label.textColor = UIColor.Ledger.selected
}

All 2 comments

Answer for self & others in the future:

self.changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
    oldCell?.label.textColor = UIColor.Ledger.content
    newCell?.label.textColor = UIColor.Ledger.selected
}

Answer with fade transition

let first: UIColor = .accent
let second: UIColor = .plainText
oldCell?.label.textColor = UIColor.blend(
    color1: progressPercentage > 0.5 ? first : second, intensity1: 1.0 - progressPercentage,
    color2: progressPercentage > 0.5 ? second : first, intensity2: progressPercentage
)
newCell?.label.textColor = UIColor.blend(
    color1: progressPercentage > 0.5 ? second : first, intensity1: 1.0 - progressPercentage,
    color2: progressPercentage > 0.5 ? first : second, intensity2: progressPercentage
)

and add this: (code from stackoverflow)

extension UIColor {
    static func blend(color1: UIColor, intensity1: CGFloat = 0.5, color2: UIColor, intensity2: CGFloat = 0.5) -> UIColor {
        let total = intensity1 + intensity2
        let l1 = intensity1/total
        let l2 = intensity2/total
        guard l1 > 0 else { return color2}
        guard l2 > 0 else { return color1}
        var (r1, g1, b1, a1): (CGFloat, CGFloat, CGFloat, CGFloat) = (0, 0, 0, 0)
        var (r2, g2, b2, a2): (CGFloat, CGFloat, CGFloat, CGFloat) = (0, 0, 0, 0)

        color1.getRed(&r1, green: &g1, blue: &b1, alpha: &a1)
        color2.getRed(&r2, green: &g2, blue: &b2, alpha: &a2)

        return UIColor(red: l1*r1 + l2*r2, green: l1*g1 + l2*g2, blue: l1*b1 + l2*b2, alpha: l1*a1 + l2*a2)
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bdrelling picture bdrelling  路  14Comments

ShockUtility picture ShockUtility  路  10Comments

imadeit picture imadeit  路  16Comments

hrsalehi picture hrsalehi  路  20Comments

keyhan76 picture keyhan76  路  25Comments