标签:
self.label.automaticLinkDetectionEnabled = sender.isOn
self.label.linkDetectionTypes |= KILinkTypeOptionURL;
self.label.linkDetectionTypes ^= KILinkTypeOptionURL;
self.label.linkDetectionTypes |= KILinkTypeOptionUserHandle;
self.label.linkDetectionTypes ^= KILinkTypeOptionUserHandle;
self.label.linkDetectionTypes |= KILinkTypeOptionHashtag;
self.label.linkDetectionTypes ^= KILinkTypeOptionHashtag;
_label.systemURLStyle = YES;
_label.selectedLinkBackgroundColor = [UIColor orangeColor];
- (void)setAttributes:(nullable NSDictionary*)attributes forLinkType:(KILinkType)linkType;
给@标签添加点击事件
```objc
_label.userHandleLinkTapHandler = KILabel *label, NSString *string, NSRange range {
NSString *message = [NSString stringWithFormat:@"You tapped %@", string];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Username"
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
};
```
给#标签添加点击事件
```objc
_label.hashtagLinkTapHandler = KILabel *label, NSString *string, NSRange range {
NSString *message = [NSString stringWithFormat:@"You tapped %@", string];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Hashtag"
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
};
```
给URL添加点击事件
```objc
_label.urlLinkTapHandler = KILabel *label, NSString *string, NSRange range {
// Open URLs
[self attemptOpenURL:[NSURL URLWithString:string]];
};
if (safariCompatible && [[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Problem"
message:@"The selected link cannot be opened."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}
}
```
标签:
原文地址:http://www.cnblogs.com/sg6548676/p/KILabel.html