Tipo de estiramiento y kerning, no funciona en Storyboard con @IBDesignable
Aquí hay unIBLabel
que rastrea / estira la fuente.
Funciona perfectamente en la construcción. Pero el cambio no se muestra en vivo en 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
}
}
El simulador a la derecha funciona perfecto.
En realidad no se muestra en vivo en Storyboard (ver a la izquierda).
Conjetura salvaje, ¿me estoy perdiendo una función de inicialización?
¿O cuál podría ser el problema?
Nota: establezca el tamaño de fuente para adaptarse a la altura:
Es posible que desee establecer el tamaño de fuente para llenar el marco de la etiqueta en todos los dispositivos. Para guardar su escritura aquí hay una clase que "señala la altura", el seguimiento y el estiramiento:https://stackoverflow.com/a/37277874/294884