
首先创建一个工程,命名为CopyToClipboardDemo。打开工程,我们在storyboard中添加一个label和button,label中显示的是我们要复制的文字
.h
NS_ASSUME_NONNULL_BEGIN
@interface GHAttributesLabel : UILabel
typedef void(^GHAttributesBlock)(NSRange poinRange)
/**
@param text 传入富文本类型的字符串
@param actionText 要响应事件的字符串
*/
/**
点击事件回调
*/
@property (nonatomic , copy) GHAttributesBlock actionBlock
.m
//
// GHAttributesLabel.m
// GHAttributesLabelDemo
//
// Created by zhaozhiwei on 2019/1/20.
// Copyright © 2019年 GHome. All rights reserved.
//
@interface GHTextView : UITextView
@end
@implementation GHTextView
@end
@interface GHAttributesLabel()<UITextViewDelegate>
@property (nonatomic , strong) GHTextView *textView
@property (nonatomic , copy) NSString *actionText
/** <#注释#>*/
@property (nonatomic, assign) NSRange range
@end
@implementation GHAttributesLabel
//return YES
}
@end
使用
-(void)test{
GHAttributesLabel *attributesLabel = [[GHAttributesLabel alloc]initWithFrame:CGRectMake(10, 200, [UIScreen mainScreen].bounds.size.width - 20, 250)]
//NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:temp]
// NSRange range = [temp rangeOfString:actionStr]
//NSLog(@"range%@",NSStringFromRange(range))
NSArray *actionArr = [self rangeOfSubString:actionStr inString:temp]
NSLog(@"===:%@",[self rangeOfSubString:actionStr inString:temp])
for (int i = 0i <actionArr.counti++) {
NSValue *value = actionArr[i]
NSRange actionRange = [value rangeValue]
[attrStr addAttribute:NSLinkAttributeName
value:actionStr
range: actionRange]
}
}
}
return rangeArray
}
-(NSMutableAttributedString *)keyWords:(NSString *)keyWords withKeyWordsColor:(UIColor *)color
{
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)