我现在可以回答自己的问题:我正在使用 UITextView
代替 UILabel
现在。我格式化了 UITextView
看起来和表现得像我的标签,并添加了:
UITextView *textView = [[UITextView alloc] init];
textView.scrollEnabled = NO;
textView.editable = NO;
textView.textContainer.lineFragmentPadding = 0;
textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
textView.delegate = self;
不要忘记设置代表,您必须实施 UITextViewDelegate
呢现在我们实施代表方法:
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)url inRange:(NSRange)characterRange
{
return YES;
}
这会自动打开提供的 NSURL
- 从我的问题/点击中的问题中列出属性字符串。
请记住:这仅在iOS 7上起作用,对于遗产支持,您需要外部库
更新:
制作 UITextView
s的表现就像标签最终完全混乱,我偶然发现了一些丑陋的iOS behaviours。我最终使用了 tttattribedlabel 图书馆很棒,允许我使用标签而不是 UITextView
s。