Tipo de alongamento e kerning, não funciona no Storyboard com @IBDesignable
Aqui está umIBLabel
que rastreia / estica a fonte.
Funciona perfeitamente na compilação. Mas a mudança não é exibida ao vivo no Storyboard.
// UILabel, but you can set
// the tracking (that's the overall amount of space between all letters)
// and streching (actually squeeze or stretch the letters horizontally)
// Note: it's very common that typographers need you to adjust these.
import UIKit
@IBDesignable
class StyledLabel: UILabel
{
@IBInspectable var tracking:CGFloat = 0.8
// values between about 0.7 to 1.3. one means normal.
@IBInspectable var stretching:CGFloat = -0.1
// values between about -.5 to .5. zero means normal.
override func awakeFromNib()
{
let ats = NSMutableAttributedString(string: self.text!)
let rg = NSRange(location: 0, length: self.text!.characters.count)
ats.addAttribute(
NSKernAttributeName, value:CGFloat(tracking), range:rg )
ats.addAttribute(
NSExpansionAttributeName, value:CGFloat(stretching), range:rg )
self.attributedText = ats
}
}
O simulador à direita funciona perfeitamente.
Na verdade, ele não é exibido ao vivo no Storyboard (veja à esquerda).
Acho que estou faltando uma função de inicialização?
Ou qual poderia ser o problema?
Nota - defina o tamanho da fonte para caber na altura:
Você pode definir o tamanho da fonte para preencher o quadro de etiqueta em todos os dispositivos. Para economizar digitação, aqui está uma classe que "aponta para a altura", acompanhando e esticando:https://stackoverflow.com/a/37277874/294884