我要讓標籤格式線標籤文本字的不同大小如何利用核心文本框架如何利用核心文本
請出示此類型這個動感的外形設置在IOS不同的UILabel文本行不同的字體樣式在動感的外形格式生成的Dynamic arrange label textDiffent font style arrange
請建議在coustom庫,使這種類型的格式
我要讓標籤格式線標籤文本字的不同大小如何利用核心文本框架如何利用核心文本
請出示此類型這個動感的外形設置在IOS不同的UILabel文本行不同的字體樣式在動感的外形格式生成的Dynamic arrange label textDiffent font style arrange
請建議在coustom庫,使這種類型的格式
我只是告訴你用NSAttributedString的方向,你必須找出像正確的字體,大小的細節休息,樣式,行距等(提示:chec ķNSMutableParagraphStyle)
let attr = NSMutableAttributedString(string: "")
attr.appendAttributedString(NSAttributedString(string: "The\n", attributes: [NSFontAttributeName: UIFont.boldSystemFontOfSize(60), NSForegroundColorAttributeName: UIColor.greenColor()]))
attr.appendAttributedString(NSAttributedString(string: "HAPPINESS OF\n", attributes: [NSFontAttributeName: UIFont.systemFontOfSize(45), NSForegroundColorAttributeName: UIColor.redColor()]))
attr.appendAttributedString(NSAttributedString(string: "YOUR LIFE\n", attributes: [NSFontAttributeName: UIFont.italicSystemFontOfSize(40), NSForegroundColorAttributeName: UIColor.purpleColor()]))
attr.appendAttributedString(NSAttributedString(string: "DEPENDS UPON", attributes: [NSFontAttributeName: UIFont.boldSystemFontOfSize(15), NSForegroundColorAttributeName: UIColor.brownColor()]))
label.attributedText = attr
@RGE是的,不是讓可能的,但我想在「你的生活」中將角色空間製作成長度等於長度上等長的線條長度「HAPPINESS」。 – Keyur
使用Objective-C,你需要做4 NSMutableAttributedString用不同的字體名稱和大小,然後才能得到想要的結果用「appendAttributedString」追加他們。使用這種方法,您只需爲所有字符串製作一幀。
請參閱下面的代碼以供參考。
//frame that contains all text
textFrame = [[UILabel alloc] init];
[textFrame setTextAlignment:NSTextAlignmentCenter];
[textFrame setNumberOfLines:0];
[self.view addSubview:textFrame];
NSString *text1 = @"THE";
NSString *text2 = @"\nHAPPINESS OF";
NSString *text3 = @"\nYOUR LIFE";
NSString *text4 = @"\nDEPENDS UPON";
//change font name and size according to your need.
UIFont *text1Font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:10];
NSMutableAttributedString *attributedString1 =
[[NSMutableAttributedString alloc] initWithString:text1 attributes:@{
NSFontAttributeName : text1Font}];
NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setAlignment:NSTextAlignmentCenter];
[paragraphStyle1 setLineSpacing:4];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [attributedString1 length])];
UIFont *text2Font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:16];
NSMutableAttributedString *attributedString2 =
[[NSMutableAttributedString alloc] initWithString:text2 attributes:@{NSFontAttributeName : text2Font }];
NSMutableParagraphStyle *paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle2 setLineSpacing:4];
[paragraphStyle2 setAlignment:NSTextAlignmentCenter];
[attributedString2 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle2 range:NSMakeRange(0, [attributedString2 length])];
UIFont *text3Font = [UIFont fontWithName:@"HelveticaNeue" size:14];
NSMutableAttributedString *attributedString3 =
[[NSMutableAttributedString alloc] initWithString:text3 attributes:@{NSFontAttributeName : text3Font }];
NSMutableParagraphStyle *paragraphStyle3 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle3 setAlignment:NSTextAlignmentCenter];
[attributedString3 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle3 range:NSMakeRange(0, [attributedString3 length])];
UIFont *text4Font = [UIFont fontWithName:@"HelveticaNeue" size:14];
NSMutableAttributedString *attributedString4 =
[[NSMutableAttributedString alloc] initWithString:text4 attributes:@{NSFontAttributeName : text4Font }];
NSMutableParagraphStyle *paragraphStyle4 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle4 setAlignment:NSTextAlignmentCenter];
[attributedString4 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle4 range:NSMakeRange(0, [attributedString4 length])];
[attributedString1 appendAttributedString:attributedString2];
[attributedString1 appendAttributedString:attributedString3];
[attributedString1 appendAttributedString:attributedString4];
[textFrame setAttributedText:attributedString1];
[textFrame sizeToFit];
//change frame size as per your need.
[textFrame setFrame:CGRectMake(10, 0, 136, 97)];
使用NSAttributedString與label.attributedText代替label.text – RJE
我用NSAttributed字符串,但不進行適當的甲這樣的..所以建議其他option..or方法 – Keyur