Closed garrialmighty closed 7 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.
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. :)
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.
As @ftvs said, this is somewhat supported by setting the attributedText
in the changeCurrentIndexProgressive
block.
Cheers
Currently the ButtonBarViewCell only uses plain text