有没有办法限制NSAttributedString段落中的行数?我在NSAttributedString
中附加了两个字符串,我希望它们最多为 3 行,第一个字符串将是 1-2 行,如果需要则截断。第二个字符串应该总是在最后一行
像:
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
第一个字符串取前 3 行并将第二个字符串推出标签。
如何将第一个字符串段落限制为 2 行?