dzenbot / DZNSegmentedControl

A drop-in replacement for UISegmentedControl for showing counts, to be used typically on a user profile

Home Page:https://www.cocoacontrols.com/controls/dznsegmentedcontrol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for custom NSNumberFormatter

ndmeiri opened this issue · comments

There are a couple ways this could be implemented.

  • An @property on each instance of DZNSegmentedControl
  • An optional delegate method that asks for a custom NSNumberFormatter for each segment index. This would allow, for example, number values to be displayed in one segment and currency values in another segment.

Which do you think would be best?

I don't think having different formatting for multiple segments is something very common. A segmented control is supposed to be used as a filter or section control, for displaying related content.

I tend to think that if we support custom NSNumberFormatter, it should either be applied to every instance of DZNSegmentedControl, or each instance by separate, but disregarding segments.

If that's the case, I'm definitely in favor of a @property more than a delegate pattern. This property should actually override the defaultFormatter. Don't you agree?

After discussion in #20 and #2 I think it's safe to rule out the delegate method option. Yes; If the segmented control is used properly then there will almost never be a need for different formatting for multiple segments. So I agree that the @property should override the defaultFormatter.

If a single number formatter is used for every instance of DZNSegmentedControl, it may be unclear why an instance's format is a certain way because the LOC that set the format may be in an entirely different function or even class. Therefore, I think we should opt for one custom NSNumberFormatter for each instance, disregarding individual segments.

Please see pull request #22.
(By the way, is there a way to "respond" to an issue with a specific pull request?)

Yes, you can mention the issue id in the commit message:
Add support for custom NSNumberFormatter from #22

You can also close an issue with the commit message:
Take a look at Github's docs here

Closed after merge of #22
Thank for this great addition!