Created
February 16, 2015 12:32
-
-
Save yoonchulkoh/c3db45d11d57c3dae884 to your computer and use it in GitHub Desktop.
UILabelで行間を調節したい。ただし、折り返しの場合は行間はデフォルトで。 ref: http://qiita.com/y_koh/items/4f6c6eb3d8c8cd691c81
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
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init]; | |
NSArray *texts = [text componentsSeparatedByString:@"\n"]; | |
int i = 0; | |
for (NSString *text in texts) { | |
if (i > 0) { | |
// 行間用の改行を追加 | |
NSMutableAttributedString *lf = [[NSMutableAttributedString alloc] initWithString:@"\n\n"]; | |
UIFont *font = [UIFont systemFontOfSize:4.0f]; | |
[lf addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, lf.length)]; | |
[attributedString appendAttributedString:lf]; | |
} | |
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text]; | |
UIFont *font = [UIFont systemFontOfSize:12.0f]; | |
[attributedText addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, attributedText.length)]; | |
[attributedString appendAttributedString:attributedText]; | |
i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment