Created
March 28, 2015 17:55
-
-
Save loganwright/6829a11b8c555a722450 to your computer and use it in GitHub Desktop.
Outlined Text Label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <UIKit/UIKit.h> | |
| @interface LGOutlinedTextLabel : UILabel | |
| @property (strong, nonatomic) UIColor *outlineColor; | |
| @property (nonatomic) CGFloat outlineWidth; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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