Swift51.com
Swift 头像
Swift  2016-09-11 20:12

Swift 格式化库 Format

回复:0  查看:5358  感兴趣:20  赞:0  

Swift 格式化库 Format,可以对数字、货币、地址、十六进制颜色进行格式化。

示例代码:

let formattedNumber = 45.format(Decimals.Two) // 45.00

let frLocale = NSLocale(localeIdentifier: "FR")
let gbLocale = NSLocale(localeIdentifier: "GB")
let formattedFRNumber = 99.format(Currency.EUR, locale: frLocale) // 99,00 €
let formattedGBNumber = 99.format(Currency.GBP, locale: gbLocale) // £ 99.00

Decimals.Three // 10.123
Currency.USD // $10.12
General.Ordinal // 10th (iOS9+ only)
General.SpellOut // ten point one two three
General.Distance // 30 feet
Mass.Person // 67 kg

let address = placemark.format()

let color = ColorFormatter().format("2ba134")

相关开源代码