Giter VIP home page Giter VIP logo

ybattributetexttapaction's Introduction

YBAttributeTextTapAction

  • 一行代码添加文本点击事件

效果图

(演示效果)

Swfit版本(最新版还未更新,可直接集成OC版本)

https://github.com/lyb5834/YBAttributeTextTapForSwfit.git

使用方法

  • #import "UILabel+YBAttributeTextTapAction.h"
  • 先设置 label.attributedText = ?????
  • 有2种回调方法,第一种是用代理回调,第二种是用block回调
  • 代理回调
  • 1.传入要点击的字符串数组
[label yb_addAttributeTapActionWithStrings:@[@"xxx",@"xxx"] delegate:self];
  • 2.传入要点击的range数组
[label yb_addAttributeTapActionWithRanges:@[NSStringFromRange(range1),NSStringFromRange(range2)] delegate:self]
  • block回调
  • 1.传入要点击的字符串数组
[label yb_addAttributeTapActionWithStrings:@[@"xxx",@"xxx"] tapClicked:^(UILabel *label,NSString *string, NSRange range,NSInteger index) {  coding more... }];
  • 2.传入要点击的range数组
[label yb_addAttributeTapActionWithRanges:@[NSStringFromRange(range1),NSStringFromRange(range2)] tapClicked:^(UILabel *label,NSString *string, NSRange range,NSInteger index) {  coding more... }];

CocoaPods支持

  • 只需在podfile中输入 pod 'YBAttributeTextTapAction' 即可

V3.0.3版本

  • 增加yb_removeAttributeTapActions方法,可以删除label上所有的附加点击事件,一般用于复用的cell,防止label上还存在不必要的点击事件

V3.0.2版本

  • 修复了在8.0系统上crash 的bug

V3.0.1版本

  • 修复字符串中有多个"\n"符号时计算不准确的bug

V3.0.0版本

  • 重构计算文字坐标的算法,点击准确率大大提升(再大的文本都不怕啦)
  • 重构API,回调参数更多
  • 增加传入range数组的API,可以指定range进行触发
  • 增加设置点击高亮色和是否扩大点击区域的API,麻麻再也不用担心我手指粗点不到啦
  • 重构demo,介绍更详细,用法更丰富
  • 修复一个页面多次调用会相互影响的bug
  • 修复在label上添加手势无效的bug

问题总结

  • 因为UILabel的封装,有些属性不能实现,在此说一下一些提的比较多的问题

必须设置字体属性,不然点击范围会不准确,重要的事情说三遍

必须设置字体属性!必须设置字体属性!必须设置字体属性!

eg:

[totalStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:orginFont] range:NSMakeRange(0, string.length)];
  • 关于文字排版的正确设置方式,设置label.textAlignment = NSTextAlignmentCenter会导致点击失效,正确的设置方法是
    NSMutableParagraphStyle *sty = [[NSMutableParagraphStyle alloc] init];
   sty.alignment = NSTextAlignmentCenter;
   [attributedString addAttribute:NSParagraphStyleAttributeName value:sty range:NSMakeRange(0, text.length)];

版本支持

  • xcode6.0+

  • 如果您在使用本库的过程中发现任何bug或者有更好建议,欢迎@issues 或联系本人email [email protected]

ybattributetexttapaction's People

Contributors

lyb5834 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.