我需要支持通过Interface (IB)添加的一些标签的自定义kerning。自定义类在IB中的标签上设置,文本也在那里设置。试图用text属性覆盖attributedText属性的尝试不起作用。
对于我的UIButton子类来说,这很好,但是类似的技术并不适用于UILabel。
attributedText属性在awakeFromNib或drawRect:rect中设置时似乎没有任何影响。
示例
class KernedLabel < UILabel
def awakeFromNib
super
attributed_text = NSMutableAttributedString.alloc
.initWithString("Atributed Text")
attributed_text.addAttribute(NSKernAttributeName,
value: 1.0,
range: [0, attributed_text.length])
attributedText = attributed_text
end
end发布于 2013-12-14 14:29:46
您的代码对我来说很好,只需做一个小改动:您需要使用self.attributedText = (在self上调用该方法):
def awakeFromNib
super
attributed_text = NSMutableAttributedString.alloc
.initWithString("Atributed Text")
attributed_text.addAttribute(NSKernAttributeName,
value: 1.0,
range: [0, attributed_text.length])
self.attributedText = attributed_text
endhttps://stackoverflow.com/questions/20577664
复制相似问题