我正在使用 Storyboard 来设置 UILabel
的行数 (4) 和换行符(截尾)。
This is what i have right now:
我的问题是如何截断/触发截断?
This is what i want to achieve:
更新:
只是为了让我的问题更清楚。
我不想像默认 UILabel
的行为那样剪切 UILabel
中的实际字符串。
使用 NSLog(@"%@", myLabel.text);
时第一张图片生成的日志是分配给它的完整字符串,这就是我试图实现的行为.
在我的例子中是:
A little girl was talking to her teacher about whales. The teacher said it was physically impossible for a whale to swallow a human because even though it was a very large mammal.
---
Making my question clearer:
如何在不剪切实际的情况下截断/触发截断 NSString
分配给它?
或者可能会解决这个问题,这有可能吗?
最佳答案
您可以使用 TTTAttributedLabel图书馆
例如:
声明:
@property (strong, nonatomic) IBOutlet TTTAttributedLabel *lblTT;
带有 setAttributedTruncationToken
的示例代码:
NSDictionary *attr = @{NSForegroundColorAttributeName : [UIColor redColor]};
NSAttributedString *str = [[NSAttributedString alloc] initWithString:@"...Continue Reading" attributes:attr];
[self.lblTT setAttributedTruncationToken:str];
希望对你有所帮助。
如果您不想使用现成的类(class),请检查此答案:How to add button to the end of text like Facebook's "Continue reading"?
关于ios - UILabel 换行截尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31420543/