Created
September 6, 2015 03:44
-
-
Save warriorg/24673051e8c3d101b999 to your computer and use it in GitHub Desktop.
UILabel UITextField调整行间距
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)setLineSpacing:(CGFloat)spacing label:(UILabel *)label | |
{ | |
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:label.text]; | |
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | |
[paragraphStyle setLineSpacing:spacing]; | |
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [label.text length])]; | |
[label setAttributedText:attributedString]; | |
[label sizeToFit]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment