Created
February 3, 2015 09:56
-
-
Save mlabraca/6fe04139eedae5dac954 to your computer and use it in GitHub Desktop.
Adds shadow to UILabel using NSMutableAttributedString
This file contains 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
- (void) addShadowToTextForLabel:(UILabel *)label withColor:(UIColor *)shadowColor andBlurRadius:(CGFloat)blurRadius | |
{ | |
NSMutableAttributedString* attString = [[NSMutableAttributedString alloc] initWithString:label.text]; | |
NSRange range = NSMakeRange(0, [attString length]); | |
[attString addAttribute:NSFontAttributeName value:label.font range:range]; | |
[attString addAttribute:NSForegroundColorAttributeName value:label.textColor range:range]; | |
NSShadow* shadow = [[NSShadow alloc] init]; | |
shadow.shadowColor = shadowColor; | |
shadow.shadowOffset = CGSizeMake(0.0f, 0.0f); | |
shadow.shadowBlurRadius = blurRadius; | |
[attString addAttribute:NSShadowAttributeName value:shadow range:range]; | |
label.attributedText = attString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment