To run the example project, clone the repo, and run pod install from the Example directory first.
ZLTTTAttributedLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ZLTTTAttributedLabel' NSString *text = @"登录或注册账号即视为同意<h>《用户协议》[@1]<h/>和<h>《隐私政策》[@2]<h/>";
ZLTTTAttributedLabel *label = [[ZLTTTAttributedLabel alloc] initWithText:text attributes:^(NSMutableAttributedString * _Nonnull mutableAttributedString) {
//设置文本默认属性
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.lineBreakMode = NSLineBreakByWordWrapping;
style.alignment = NSTextAlignmentRight;
[mutableAttributedString addAttributes:@{
NSFontAttributeName: [UIFont systemFontOfSize:18],
NSParagraphStyleAttributeName: style,
(id)kCTForegroundColorAttributeName : (id)[UIColor blackColor].CGColor,
} range:NSMakeRange(0, mutableAttributedString.length)];
} highlightAttributes:^(NSArray<ZLTagMatch *> * _Nonnull items) {
//设置高亮文本属性
[items makeObjectsPerformSelector:@selector(addAttributes:) withObject:@{
(id)kCTForegroundColorAttributeName : (id)[UIColor redColor].CGColor,
NSFontAttributeName: [UIFont boldSystemFontOfSize:20],
}];
} tapAction:^(ZLURLItem * _Nonnull item) {
//点击事件回调
UIAlertController *alert = [UIAlertController alertControllerWithTitle:item.text
message:item.tagId
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}];
label.textAlignment = NSTextAlignmentCenter;
label.numberOfLines = 0;fanpeng, [email protected]
ZLTTTAttributedLabel is available under the MIT license. See the LICENSE file for more info.


