货币符号使决策属性串
问题描述:
,同时在项目的工作我的任务是变相的货币兑换成Niria,我成功地把它们转换成Niria但是当我必须表明它归结出现问题后, 当我转换简单字符串归属一个strik通过从符号中缺失货币符号使决策属性串
let balance = "₦ 450.00"
let myMutableString = NSMutableAttributedString(string: balance, attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 48)])
if balance.contains(".") {
myMutableString.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 22)], range: NSRange(location: balance.length - 2, length: 2))
}
答
我相信这是新旧金山字体的问题。
一种解决方法是使用黑体
let balance = "₦ 450.00"
let myMutableString = NSMutableAttributedString(string: balance, attributes: [NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 48.0)!])
if balance.containsString(".") {
myMutableString.addAttributes([NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 22.0)!], range: NSRange(location: balance.characters.count - 2, length: 2))
}
注:雨燕3.0
:不幸的是,我没有,我仍然在使用雨燕2.2编辑迁移到斯威夫特3
let balance = "₦ 450.00" let myMutableString = NSMutableAttributedString(string: balance, attributes: [NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 48.0)!]) if balance.contains("."){ myMutableString.addAttributes([NSFontAttributeName: UIFont(name: "Helvetica Neue", size: 22.0)!], range: NSRange(location: balance.characters.count - 2, length: 2)) }
你是对的这是系统字体的问题,希望完全苹果会做一些关于这个 –