Skip to content

Instantly share code, notes, and snippets.

@yoonchulkoh
Created February 16, 2015 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoonchulkoh/c3db45d11d57c3dae884 to your computer and use it in GitHub Desktop.
Save yoonchulkoh/c3db45d11d57c3dae884 to your computer and use it in GitHub Desktop.
UILabelで行間を調節したい。ただし、折り返しの場合は行間はデフォルトで。 ref: http://qiita.com/y_koh/items/4f6c6eb3d8c8cd691c81
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