我需要在我的视图中动态设置可点击 URL 的文本和值。
我已经使用NSTextView
,但设置字体似乎非常复杂,我无法弄清楚如何使文本居中:
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString:@"Click me"
attributes:[[NSDictionary alloc] initWithObjectsAndKeys:[NSFont fontWithName:@"Lucida Grande" size:14], NSFontAttributeName, nil]];
[attrString beginEditing];
[attrString addAttribute:NSLinkAttributeName value:@"http://example.com" range:NSMakeRange(0, [attrString length])];
[attrString endEditing];
[[self.downloadLinkTextField textStorage] setAttributedString:attrString];
- 我做错了吗?我在 URL 的对象库中找不到任何内容。
- 链接是否可以居中对齐?