是否有限制段落中行數的方法NSAttributedString?
我追加了兩個字符串NSAttributedString我希望它們最多3行,第一個字符串將是1-2行,如果需要截斷。第二個字符串應該總是在最後一行
喜歡的東西:
限制NSAttributedString行數
this is my first string
if its too long i't will get trun...
But this is my second string
我所做的是:
// First string
NSAttributedString *first = [[NSAttributedString alloc] initWithString:@"this is my first string if its too long i't will get trunticated"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:17.0]];
[str appendAttributedString:first];
// New line
[str appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
// Add photo count
NSAttributedString *second = [[NSAttributedString alloc] initWithString:@"But this is my second string"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:14.0]}];
[str appendAttributedString:second];
但結果是:
this is my first string
if its too long i't will get
trunticated
的第一個字符串取前三行,並將第二個字符串從標籤中移出。
我如何限制第一個字符串段爲2行?
你能解決這個問題嗎? – ZeMoon 2015-04-27 07:36:47
Nop ...現在我只是使用兩個不同的標籤 – ItayAmza 2015-04-27 10:59:00