承接Label裡的字距,也可以調整行距!讓界面越來越好看吧~
原本沒有行距特性的樣子:
/**
Theme: Character Spacing in UILabel
IDE: Xcode 5
Language: Objective C
Date: 103/02/13
Author: HappyMan
Blog: https://cg2010studio.wordpress.com/
*/
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];
label.numberOfLines = 0;
NSString *string = @"開發iPhone APP真是有趣!我要逍遙遊~";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
float spacing = 17.0f;
// 加入字距特性
[attributedString addAttribute:NSKernAttributeName
value:@(spacing)
range:NSMakeRange(0, [string length])];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:40];
// 加入行距特性
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];
label.attributedText = attributedString;
[self.view addSubview:label];
}
行距也可以想多高就有多高!
接下來就是微調到使用者覺得舒適的樣子吧!



Comments on: "[iOS] Label裡的行距" (7)
[…] 此外,可參考先前介紹的文章:多重文字屬性 (Multiple Text Attribute)、LABEL裡的行距、LABEL裡的字距。 […]
讚讚
你覺得字型是不是個好生意?
讚讚
應該說是「設計」,字型美觀點會讓使用者體驗更好喔! 😉
讚讚
世界有很多語言, 設計各種語言的字型用在各種地方, 像CSS 設計…. 這會是個好生意嗎?
讚讚
字體本身的藝術我覺得會被包含在設計中,之前有看過有在賣字體,很多已經變成免費了~
讚讚
有 font layout engine… 的生意, 這應用大嗎?
讚讚
那方面我就沒研究嚕~
讚讚