, Kern , , UIFont/CFFont . . , , .4 .
override func viewDidLoad() {
super.viewDidLoad()
self.label.addObserver(self, forKeyPath: "text", options: [.New], context: nil)
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if object === self.label,
let change = change,
let newValue = change[NSKeyValueChangeNewKey] as? NSString,
let attributedText = self.label.attributedText?.mutableCopy() as? NSMutableAttributedString {
let matchRange = newValue.rangeOfString(".4")
if matchRange.location == NSNotFound {
attributedText.removeAttribute(NSKernAttributeName, range: NSMakeRange(0, newValue.length))
} else {
let kernRange = NSMakeRange(matchRange.location, matchRange.length - 1)
attributedText.setAttributes([NSKernAttributeName: 10], range: kernRange)
}
self.label.attributedText = attributedText
}
}