Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't draw zero value label #197

Closed
liebeskind opened this issue Jul 9, 2015 · 5 comments
Closed

Don't draw zero value label #197

liebeskind opened this issue Jul 9, 2015 · 5 comments

Comments

@liebeskind
Copy link

Any know a way to not draw the value labels that are 'zero' in a horizontal bar graph?

@danielgindi
Copy link
Collaborator

NSNumberFormatter is a very strong factory.

@danielgindi
Copy link
Collaborator

Meaning you can set zeroSymbol to "", which by default is "0"
https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumberFormatter_Class/index.html#//apple_ref/occ/instp/NSNumberFormatter/zeroSymbol

Or, make a subclass of NSNumberFormatter, and format the numbers however you like.

@liebeskind
Copy link
Author

Brilliant! That worked. Thanks Daniel. For others that are interested in doing something similar, here is my fairly simple NSNumberFormatter subclass.

class NoStyleFormatter: NSNumberFormatter {
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override init() {
        super.init()
        self.numberStyle = .NoStyle
        self.zeroSymbol = ""
    }

    // Swift 1.2 or above
    static let sharedInstance = NoStyleFormatter()
}

@danielgindi
Copy link
Collaborator

Man that's over-complex.
Just do:

var noZeroFormatter = NSNumberFormatter()
noZeroFormatter.zeroSymbol = ""

@danielgindi
Copy link
Collaborator

You can subclass - but for changes that you don't have properties for. Luckily you have properties for anything you can dream about...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants