标签:types 超链接 test ipa cto sel tac 代理 handle
对于 Label 需要支持复制、超链接监听最好的方案就是使用UITextView 代替Label
设置TextView支持超链接
self.contentTextView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0); self.contentTextView.delegate = self; self.contentTextView.editable = NO; self.contentTextView.showsVerticalScrollIndicator = NO; self.contentTextView.dataDetectorTypes = UIDataDetectorTypeLink;
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
if ([self.delegate respondsToSelector:@selector(clickUrl:)]) {
[self.delegate clickUrl:[URL.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
NSLog(@"%@", URL.absoluteString);
return NO;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
if ([self.delegate respondsToSelector:@selector(clickUrl:)]) {
[self.delegate clickUrl:[URL.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
return NO;
}
控制器里面 实现代理
- (void)clickUrl:(NSString *)url {
UIAlertControllerStyle style = UIAlertControllerStyleActionSheet;
if ([PhoneUtil isPadDevice]) { // 适配iPad
style = UIAlertControllerStyleAlert;
}
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:url message:nil preferredStyle:style];
// 处理复制
UIAlertAction *copyAction = [UIAlertAction actionWithTitle:getStringByKey(@"string_key_616") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = url;
}];
// 处理链接点击应用内跳转
UIAlertAction *openAction = [UIAlertAction actionWithTitle:getStringByKey(@"string_key_1370") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Setting" bundle:[NSBundle mainBundle]];
WebViewVC *vc=[sb instantiateViewControllerWithIdentifier:@"WebViewVC"];
vc.url = url;
[self.navigationController pushViewController:vc animated:YES];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:getStringByKey(@"string_key_219") style:UIAlertActionStyleCancel handler:nil];
[alertVC addAction:copyAction];
[alertVC addAction:openAction];
[alertVC addAction:cancelAction];
[self.navigationController presentViewController:alertVC animated:YES completion:nil];
}
标签:types 超链接 test ipa cto sel tac 代理 handle
原文地址:http://www.cnblogs.com/10-19-92/p/7693592.html