码迷,mamicode.com
首页 > 其他好文 > 详细

KILabel

时间:2016-06-03 14:12:06      阅读:576      评论:0      收藏:0      [点我收藏+]

标签:

  • 功能
    • 让labe具有超链接效果
  • 链接

<常用属性>

  • 开启关闭标签的点击事件self.label.automaticLinkDetectionEnabled = sender.isOn
  • 打开URL点击事件self.label.linkDetectionTypes |= KILinkTypeOptionURL;
  • 关闭URL点击事件self.label.linkDetectionTypes ^= KILinkTypeOptionURL;
  • 打开@标签点击事件self.label.linkDetectionTypes |= KILinkTypeOptionUserHandle;
  • 闭关@标签点击事件self.label.linkDetectionTypes ^= KILinkTypeOptionUserHandle;
  • 打开#标签事件self.label.linkDetectionTypes |= KILinkTypeOptionHashtag;
  • 关闭#标签事件self.label.linkDetectionTypes ^= KILinkTypeOptionHashtag;
  • 设置URL下划线_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]];
    };

    • (void)attemptOpenURL:(NSURL *)url { BOOL safariCompatible = [url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"];

    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];
    }
    }
    ```

KILabel

标签:

原文地址:http://www.cnblogs.com/sg6548676/p/KILabel.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!