@@ -204,6 +204,8 @@ import UIKit
204204 @IBInspectable public var referenceLineUnits : String ?
205205 /// The number of decimal places that should be shown on the reference line labels.
206206 @IBInspectable public var referenceLineNumberOfDecimalPlaces : Int = 0
207+ /// The NSNumberFormatterStyle that reference lines should use to display
208+ @IBInspectable public var referenceLineNumberStyle : NSNumberFormatterStyle = . NoStyle
207209
208210 // Data Point Labels
209211 // #################
@@ -506,6 +508,7 @@ import UIKit
506508 referenceLineView? . labelFont = self . referenceLineLabelFont
507509 referenceLineView? . labelColor = self . referenceLineLabelColor
508510 referenceLineView? . labelDecimalPlaces = self . referenceLineNumberOfDecimalPlaces
511+ referenceLineView? . labelNumberStyle = self . referenceLineNumberStyle
509512
510513 referenceLineView? . setRange ( self . range)
511514 self . addSubview ( referenceLineView!)
@@ -1629,6 +1632,7 @@ private class ReferenceLineDrawingView : UIView {
16291632 var labelFont : UIFont = UIFont . systemFontOfSize ( 8 )
16301633 var labelColor : UIColor = UIColor . blackColor ( )
16311634 var labelDecimalPlaces : Int = 2
1635+ var labelNumberStyle : NSNumberFormatterStyle = . NoStyle
16321636
16331637 // PRIVATE PROPERTIES
16341638
@@ -1712,8 +1716,10 @@ private class ReferenceLineDrawingView : UIView {
17121716 let minLineStart = CGPoint ( x: 0 , y: self . bounds. height - bottomMargin)
17131717 let minLineEnd = CGPoint ( x: lineWidth, y: self . bounds. height - bottomMargin)
17141718
1715- let maxString = String ( format: " %. \( labelDecimalPlaces) f " , arguments: [ self . currentRange. max] ) + units
1716- let minString = String ( format: " %. \( labelDecimalPlaces) f " , arguments: [ self . currentRange. min] ) + units
1719+ let numberFormatter = referenceNumberFormatter ( )
1720+
1721+ let maxString = numberFormatter. stringFromNumber ( self . currentRange. max) ! + units
1722+ let minString = numberFormatter. stringFromNumber ( self . currentRange. min) ! + units
17171723
17181724 addLineWithTag ( maxString, from: maxLineStart, to: maxLineEnd, inPath: referenceLinePath)
17191725 addLineWithTag ( minString, from: minLineStart, to: minLineEnd, inPath: referenceLinePath)
@@ -1725,6 +1731,15 @@ private class ReferenceLineDrawingView : UIView {
17251731 return referenceLinePath
17261732 }
17271733
1734+ private func referenceNumberFormatter( ) -> NSNumberFormatter {
1735+ let numberFormatter = NSNumberFormatter ( )
1736+ numberFormatter. numberStyle = labelNumberStyle
1737+ numberFormatter. minimumFractionDigits = labelDecimalPlaces
1738+ numberFormatter. maximumFractionDigits = labelDecimalPlaces
1739+
1740+ return numberFormatter
1741+ }
1742+
17281743 private func createIntermediateReferenceLines( rect: CGRect , numberOfIntermediateReferenceLines: Int , forPath path: UIBezierPath ) {
17291744
17301745 let height = rect. size. height
@@ -1773,7 +1788,8 @@ private class ReferenceLineDrawingView : UIView {
17731788 if ( shouldAddLabelsToIntermediateReferenceLines) {
17741789
17751790 let value = calculateYAxisValueForPoint ( lineStart)
1776- var valueString = String ( format: " %. \( labelDecimalPlaces) f " , arguments: [ value] )
1791+ let numberFormatter = referenceNumberFormatter ( )
1792+ var valueString = numberFormatter. stringFromNumber ( value) !
17771793
17781794 if ( shouldAddUnitsToIntermediateReferenceLineLabels) {
17791795 valueString += " \( units) "
0 commit comments