Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created March 28, 2015 17:55
Show Gist options
  • Save loganwright/6829a11b8c555a722450 to your computer and use it in GitHub Desktop.
Save loganwright/6829a11b8c555a722450 to your computer and use it in GitHub Desktop.
Outlined Text Label
#import <UIKit/UIKit.h>
@interface LGOutlinedTextLabel : UILabel
@property (strong, nonatomic) UIColor *outlineColor;
@property (nonatomic) CGFloat outlineWidth;
@end
#import "LGOutlinedTextLabel.h"
@implementation LGOutlinedTextLabel
- (void)drawTextInRect:(CGRect)rect {
UIColor *mainTextColor = self.textColor;
CGSize shadowOffset = self.shadowOffset;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, self.outlineWidth);
CGContextSetLineJoin(c, kCGLineJoinRound);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = self.outlineColor;
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = mainTextColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect];
self.shadowOffset = shadowOffset;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment