【发布时间】:2012-02-10 04:10:16
【问题描述】:
我发现了这个小 sn-p,它允许从 NSTextView 中的文本创建链接:
-(void)setHyperlinkWithTextView:(NSTextView*)inTextView
{
// create the attributed string
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
// create the url and use it for our attributed string
NSURL* url = [NSURL URLWithString: @"http://www.apple.com"];
[string appendAttributedString:[NSAttributedString hyperlinkFromString:@"Apple Computer" withURL:url]];
// apply it to the NSTextView's text storage
[[inTextView textStorage] setAttributedString: string];
}
是否可以让链接指向我的应用程序中的某些资源,例如指向能够解释链接并分派到相应视图/控制器的特定处理程序类?
【问题讨论】:
标签: cocoa nsurl nstextview