一行代码添加文本点击事件/a fast way to implement click event text
https://github.com/lyb5834/YBAttributeTextTapForSwfit.git
#import "UILabel+YBAttributeTextTapAction.h"
label.attributedText = ?????
[label yb_addAttributeTapActionWithStrings:@[@"xxx",@"xxx"] delegate:self];
[label yb_addAttributeTapActionWithRanges:@[NSStringFromRange(range1),NSStringFromRange(range2)] delegate:self]
[label yb_addAttributeTapActionWithStrings:@[@"xxx",@"xxx"] tapClicked:^(UILabel *label,NSString *string, NSRange range,NSInteger index) { coding more... }];
[label yb_addAttributeTapActionWithRanges:@[NSStringFromRange(range1),NSStringFromRange(range2)] tapClicked:^(UILabel *label,NSString *string, NSRange range,NSInteger index) { coding more... }];
pod 'YBAttributeTextTapAction'
即可yb_removeAttributeTapActions
方法,可以删除label上所有的附加点击事件,一般用于复用的cell,防止label上还存在不必要的点击事件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]