There are a myriad of settings for NSAttributedParagraphStyle
that I can see in Interface Builder:
But none of these are for text kerning. Is there a way to adjust the text kerning in Xcode 7's Interface Builder for attributed text?
(Please don't answer with how to do this in code - I already know how to do that!)
You can actually do this without the use of a subclass through an extension.
import UIKit
@IBDesignable
extension UILabel {
@IBInspectable
public var kerning:CGFloat {
set{
if let currentAttibutedText = self.attributedText {
let attribString = NSMutableAttributedString(attributedString: currentAttibutedText)
attribString.addAttributes([NSKernAttributeName:newValue], range:NSMakeRange(0, currentAttibutedText.length))
self.attributedText = attribString
}
} get {
var kerning:CGFloat = 0
if let attributedText = self.attributedText {
attributedText.enumerateAttribute(NSKernAttributeName,
in: NSMakeRange(0, attributedText.length),
options: .init(rawValue: 0)) { (value, range, stop) in
kerning = value as? CGFloat ?? 0
}
}
return kerning
}
}
}
While this won't actually show up in interface builder it will show up and work when you run your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With