• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

用于识别Label中的@用户-话题##-链接

HYLabel

框架的作用

使用效果

  • 如图所示
  • 并且可以监听点击
  • image

使用方式

  • 导入框架
    • 直接将HYLabel.swift拖入项目
    • 该框架支持cocoapods:pod 'HYLabel', '~> 1.0.1'
  • 将UIlabel修改为HYLabel
  • 按照下列方式监听点击即可
  • OC监听方式
    self.demoLabel.userTapHandler = ^(HYLabel *label, NSString *user, NSRange range){
        NSLog(@"%@", label);
        NSLog(@"%@", user);
        NSLog(@"%@", NSStringFromRange(range));
    };
    
    self.demoLabel.linkTapHandler = ^(HYLabel *label, NSString *link, NSRange range){
        NSLog(@"%@", label);
        NSLog(@"%@", link);
        NSLog(@"%@", NSStringFromRange(range));
    };
    
    self.demoLabel.userTapHandler = ^(HYLabel *label, NSString *topic, NSRange range){
        NSLog(@"%@", label);
        NSLog(@"%@", topic);
        NSLog(@"%@", NSStringFromRange(range));
    };
  • swift监听方式
    // 监听@谁谁谁的点击
    demoLabel.userTapHandler = { (label, user, range) in
        print(label)
        print(user)
        print(range)
    }
    
    // 监听链接的点击
    demoLabel.linkTapHandler = { (label, link, range) in
        print(label)
        print(link)
        print(range)
    }
    
    // 监听话题的点击
    demoLabel.topicTapHandler = { (label, topic, range) in
        print(label)
        print(topic)
        print(range)
    }