UILabelのサブクラスを作成し、それが次のコードで構成されていKerningLabel呼び出します。
import UIKit
@IBDesignable
class KerningLabel: UILabel {
@IBInspectable var kerning: CGFloat = 0.0 {
didSet {
if attributedText?.length == nil { return }
let attrStr = NSMutableAttributedString(attributedString: attributedText!)
let range = NSMakeRange(0, attributedText!.length)
attrStr.addAttributes([NSAttributedStringKey.kern: kerning], range: range)
attributedText = attrStr
}
}
}
ラベルをドラッグします。あなたのUILabelサブクラスに変更してください。必要に応じてカーニングを調整します。 OBJ-Cで![enter image description here](https://i.stack.imgur.com/78zQG.png)
:
.h
IB_DESIGNABLE
@interface KerningLabel : UILabel
@property (nonatomic) IBInspectable CGFloat kerning;
@end
.m
@implementation KerningLabel
- (void)setKerning:(CGFloat)kerning
{
_kerning = kerning;
if(self.attributedText)
{
NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithAttributedString:self.attributedText];
[attribString addAttribute:NSKernAttributeName value:@(kerning) range:NSMakeRange(0, self.attributedText.length)];
self.attributedText = attribString;
}
}
@end
あなたは今までの道を見つけますか?それはその不在の中で目立つように見える。 – Dov
@Dov nope ...確かに! – brandonscript