2015-10-12 31 views
2

我想在另一個標籤下面顯示一個標籤的文本。儘管文本應該從第一個標籤&的右側開始,它應該在另一個標籤的下面。請告訴我可以使用ios?如何在iOS下顯示兩個以下的標籤文字?

enter image description here

+1

我認爲你會更好的使用'NSAttributedString'並向用戶添加一個粗體屬性。所以你的文本將在一個UILabel,但可以有單獨的字體大小和間距。 – kezi

回答

1

我得到了你的問題的解決方案。它是非常容易和可以理解的。

NSMutableAttributedString *mutableAttributeStr = [[NSMutableAttributedString alloc]initWithString:@"User this is just a comment.This just a comment.This just a comment."]; 

NSAttributedString *attributeStr = [[NSAttributedString alloc]initWithString:@"\n" attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:8]}]; 

[mutableAttributeStr addAttribute:NSFontAttributeName value: [UIFont fontWithName:@"Helvetica-Bold" size:14.0] range:NSMakeRange(0, 4)]; 

[mutableAttributeStr appendAttributedString:attributeStr]; 

labelTextBelowAnotherLabel.numberOfLines = 0; 

[labelTextBelowAnotherLabel setAttributedText:mutableAttributeStr]; 

以上編碼我設置了黑體加粗和字體大小爲reference.If你想改變systemBold只是改變同時也可根據您的要求設置字體大小。

謝謝你:) :)

+0

無論是否有效告訴我。如果它工作正常,請給我打勾標記並投票給我回答。因爲它對其他人很有幫助。 – user3182143

+0

非常感謝你:) – user3182143

0

是的,這是可能與storyboard.Just一張標籤使用一個標籤,並設置文本爲歸因。 enter image description here

並選擇用戶詞,然後右鍵單擊,找到名爲「Font」的選項。現在您可以選擇爲粗體,斜體,底線等。

這是在一個標籤中顯示文本的簡單方法。

推薦給你的修士!

+0

我如何使它在運行時動態,就像從服務器獲取的用戶名應該是大致的 – Techiee

+0

然後你使用NSMutableAttributedString來顯示這個。 –

1

在運行時顯示您使用NSMutableAttributedString。 例如

NSDictionary *dicAttributes = @{NSForegroundColorAttributeName:WHITE_COLOR, NSFontAttributeName: UI_DEFAULT_ROBOTO_BOLD(15.0)}; 
NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:@"here is your text which want to set" attributes:dicAttributes]; 
相關問題