Skip to content

Instantly share code, notes, and snippets.

@peerasak-u
Created August 7, 2013 14:50
Show Gist options
  • Select an option

  • Save peerasak-u/6174730 to your computer and use it in GitHub Desktop.

Select an option

Save peerasak-u/6174730 to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
@interface UILabel (TextKerning)
- (void) setText:(NSString *)text withKerning:(CGFloat)kerning;
- (void) setKerning:(CGFloat)kerning;
@end
#import "UILabel+TextKerning.h"
@implementation UILabel (TextKerning)
-(void) setText:(NSString *)text withKerning:(CGFloat)kerning
{
if ([self respondsToSelector:@selector(setAttributedText:)])
{
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
[attributedString addAttribute:NSKernAttributeName
value:[NSNumber numberWithFloat:kerning]
range:NSMakeRange(0, [text length])];
[self setAttributedText:attributedString];
}
else
[self setText:text];
}
-(void) setKerning:(CGFloat)kerning
{
[self setText:self.text withKerning:kerning];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment