本文介绍了如何使用Xcode 7中的Interface Builder调整文本字距调整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Interface Builder中可以看到 NSAttributedParagraphStyle
的无数设置:
There are a myriad of settings for NSAttributedParagraphStyle
that I can see in Interface Builder:
但这些都不是用于文本字距调整。有没有办法在Xcode 7的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?
推荐答案
您实际上可以在不使用扩展子类的情况下执行此操作。
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.
这篇关于如何使用Xcode 7中的Interface Builder调整文本字距调整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!