xmartlabs / XLPagerTabStrip

Android PagerTabStrip for iOS.
MIT License
6.98k stars 1.33k forks source link

[Feature Request] Make ButtonBarViewCell support attributed strings #212

Closed garrialmighty closed 7 years ago

garrialmighty commented 8 years ago

Currently the ButtonBarViewCell only uses plain text

colinmorelli commented 8 years ago

I just finished making some changes to my project to allow attributed strings to work. Certainly the library is flexible enough to make this happen, but you end up having to override (at the very least), configureCell (for setting the appropriate initial values) + changeCurrentIndexProgressive/changeCurrentIndex (for updating the attributed string when items are selected) + buttonBarItemSpec (for making sure the labels calculate the proper width)

Would be good to see this added.

garrialmighty commented 8 years ago

I was able to support attributed strings they way my app needed by customizing the changeCurrentIndexProgressive closure.

Would also like to see this feature in the future. Thank you for the library by the way. Saved me a lot of time implementing this the hard way. :)

ftvs commented 8 years ago

Example code:

buttonBarPagerTabStripViewController.changeCurrentIndexProgressiveBlock = ^(XLButtonBarViewCell *oldCell,
                                            XLButtonBarViewCell *newCell,
                                            CGFloat progressPercentage,
                                            BOOL indexWasChanged,
                                            BOOL fromCellRowAtIndex) {
    NSNumber *trackingAmount = @(.5f);

    oldCell.label.attributedText
        = (oldCell)
          ? [[NSAttributedString alloc] initWithString:oldCell.label.text
                                            attributes:@{NSKernAttributeName: trackingAmount}]
          : nil;
    newCell.label.attributedText
        = (newCell)
          ? [[NSAttributedString alloc] initWithString:newCell.label.text
                                            attributes:@{NSKernAttributeName: trackingAmount]
          : nil;
};

Checking for nil is necessary because the block can be called while they are nil. [NSAttributedString initWithString] crashes on nil arguments.

santiagofm commented 7 years ago

As @ftvs said, this is somewhat supported by setting the attributedText in the changeCurrentIndexProgressive block.

Cheers