rishu1992
rishu1992

Reputation: 1434

ios: Kerning for custom fonts

Can I have Kerning for custom fonts in ios for UILable and UIButton?

Below method is not working. Kerning works for system font but not for Custom fonts. Can Somebody help in solving issue?

NSMutableAttributedString *attributedString =
   [[NSMutableAttributedString alloc] initWithString:text attributes:
       @{
          NSFontAttributeName : [UIFont fontWithName:@"BebasNeue Bold" size:25],
          NSForegroundColorAttributeName : [UIColor redColor]
     }];

   [attributedString addAttribute:NSKernAttributeName
       value:[NSNumber numberWithFloat:kerning]
       range:NSMakeRange(0, [text length])];
   [self setAttributedText:attributedString];

Upvotes: 2

Views: 528

Answers (1)

MD Aslam Ansari
MD Aslam Ansari

Reputation: 1565

You can try this. It might help.

NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:@"Please test this text"];
[attributedString addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(10, 5)];
[self.label setAttributedText:attributedString];

for more solution please check the following link

How to set kerning in iPhone UILabel

I hope this helps .

Upvotes: 4

Related Questions