How to change an UILabel/UIFont's letter spacing?

后端 未结 5 1369
小蘑菇
小蘑菇 2020-12-02 12:32

I\'ve searched loads already and couldn\'t find an answer.

I have a normal UILabel, defined this way:

    UILabel *totalColors = [[[UILabel alloc] in         


        
5条回答
  •  -上瘾入骨i
    2020-12-02 13:13

    From iOS 6 you can use NSAttributedString in UILabel.

    In attributed string you can use attribute NSKernAttributeName to set letter spacing

    NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString: @"Test test test test "];
    [attrStr addAttribute:NSKernAttributeName value:@(4.0) range:NSMakeRange(0, attrStr.length)];
    
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, 300, 100)];
    label.attributedText = attrStr;
    

提交回复
热议问题