label标记关键字
来源:互联网 发布:钻石展位 淘宝首页 编辑:程序博客网 时间:2024/06/18 18:41
可以标记多组关键字 以数组方式存入
直接上代码 喜欢点赞 拿走不谢!
#import "lab_Search.h"
@implementation lab_Search
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (NSArray *)IsChinese:(NSString *)str
{
NSArray *chineses;
NSMutableArray *mChineses = [NSMutableArrayarray];
for (int i =0; i < [str length]; ++i)
{
int a = [strcharacterAtIndex:i];
if (a >0x4e00 && a < 0x9fff)
{
[mChineses addObject:[strsubstringWithRange:(NSRange){i,1}]];
}
}
chineses = mChineses;
return chineses;
}
#pragma mark -- 设置关键字
#pragma mark -- 设置关键字
-(void)attributeStringWithContent:(NSString *)content keyWords:(NSArray *)keyWords colors:(NSArray *)colors repeat:(BOOL)repeat
{
NSMutableAttributedString *attString = [[NSMutableAttributedStringalloc] initWithString:content];
if (keyWords) {
[keyWords enumerateObjectsUsingBlock:^(id obj,NSUInteger idx, BOOL *stop) {
NSMutableString *tmpString=[NSMutableStringstringWithString:content];
NSRange range=[contentrangeOfString:obj];
NSInteger location=0;
while (range.length>0) {
UIColor *color=nil;
if (!colors[0]) {
color=[UIColorcolorWithHexString:@"#00c2c9"];
}else{
color=colors[0];
}
[attString addAttribute:(NSString*)NSForegroundColorAttributeNamevalue:color range:NSMakeRange(location+range.location, range.length)];
location+=(range.location+range.length);
NSString *tmp= [tmpStringsubstringWithRange:NSMakeRange(range.location+range.length, content.length-location)];
tmpString=[NSMutableStringstringWithString:tmp];
range=[tmp rangeOfString:obj];
if (!repeat) {
break;
}
}
}];
}
self.attributedText = attString;
}
@end
- label标记关键字
- label关键字高亮 --label定制
- [标记]C++关键字详解
- swift 中的标记关键字
- html忽略标签关键字标记
- 自定义Label,设置关键字的颜色
- Html中Label标记的作用和使用介绍
- 通过label标记实现单选框点击文字也能选中
- Doxygen常用标记(关键字)合集
- ASP.NET 搜索关键字标记为红色
- Java的default、native关键字以及label简介
- label
- Label
- label
- Label
- label
- Label
- label
- CryptoDev usage demo
- UVa 11440 Help Tomisu
- printf输出字符串的一些格式
- Linux系统中的日志管理
- 2、adb常用命令
- label标记关键字
- html快速查找功能列表
- CAP理论十二年回顾:"规则"变了
- 最完整的struts.xml骨架
- 网络编程序列1——理解网络编程
- 全栈学习总结
- 你真的懂iOS的autorelease吗?
- iOS 开发,block是什么?clang -rewrite-objc反编译block,带你揭开block的神秘面纱
- 浅析人脸检测之Haar分类器方法