iosnsattributedstringnstexttab

How can I get a Decimal Tab Stop on iOS when NSTextTab on iOS doesn't offer that option?


When developing for OS X, you have the option of specifying the DecimalTabStopType to get a tab stop on the decimal point of a column of numbers. However, this option isn't available in iOS - is there some way to achieve the same affect?


Solution

  • Currently there's a built-in support for decimal tab stops, see https://developer.apple.com/documentation/uikit/nstexttab/1535107-columnterminators

    Can be used as follows

    let paragraphStyle = NSMutableParagraphStyle()
    let terms = NSTextTab.columnTerminators(for: NSLocale.current)
    let tabStop0 = NSTextTab(textAlignment: .right, location: 100, options: 
    [NSTabColumnTerminatorsAttributeName:terms])