NSMutableAttributedString的使用
1.设置字符串中数字字符串的颜色:
// 设置字符串中数字的颜色
- (void)setTextColor:(UILabel *)label FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label.text]; NSCharacterSet* nonDigits =[[NSCharacterSet decimalDigitCharacterSet] invertedSet];
int remainSecond =[[label.text stringByTrimmingCharactersInSet:nonDigits] intValue];
NSLog(@" num %d ",remainSecond); NSString *labelText = label.text; for (int i = ; i < labelText.length; i ++) {
//这里的小技巧,每次只截取一个字符的范围
NSString *a = [labelText substringWithRange:NSMakeRange(i, )];
//判断装有0-9的字符串的数字数组是否包含截取字符串出来的单个字符,从而筛选出符合要求的数字字符的范围NSMakeRange
NSArray *number = @[@"",@"",@"",@"",@"",@"",@"",@"",@"",@""];
if ([number containsObject:a]) {
[str setAttributes:@{NSForegroundColorAttributeName:SELECT_PERSON_BUTTON_COLOR,NSFontAttributeName:FONT_13} range:NSMakeRange(i, )];
}
}
label.attributedText = str;
}
2.截取某个字符串段,设置字体颜色:
- (void)setBlueColorStringWithText:(NSMutableString *)text {
NSRange startRange = [text rangeOfString:@"("];
NSRange endRange = [text rangeOfString:@")"];
NSRange range = NSMakeRange(startRange.location + startRange.length -1, endRange.location - startRange.location - startRange.length + 2);
NSDictionary *attribs = @{NSForegroundColorAttributeName: SELECT_PERSON_BUTTON_COLOR,
NSFontAttributeName:FONT_13
};
NSMutableAttributedString *textStr = [[NSMutableAttributedString alloc] initWithString:text];
[textStr setAttributes:attribs range:range];
self.deadlineLabel.attributedText = textStr;
}
NSMutableAttributedString的使用的更多相关文章
- iOS - NSMutableAttributedString富文本的实现
NSMutableAttributedString继承于NSAttributedString(带属性的字符串)能够简单快速实现富文本的效果;不多说直接上效果图和代码,通俗易懂: (一)效果图: (二) ...
- iOS中富文本NSMutableAttributedString的用法
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:@"我是富文 ...
- NSMutableAttributedString(转)
NSMutableAttributedString计算高度的问题 _label_page2_1 = [[UILabel alloc] init]; _label_page2_1.numberOfLin ...
- NSMutableAttributedString常用代码
NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNam ...
- NSMutableAttributedString 的使用
NSMutableAttributedString *msAttriStr = [[NSMutableAttributedString alloc] initWithString:[NSString ...
- objective-c NSMutableAttributedString
NSMutableAttributedString 是一个很强悍的富文本处理字符串,可以方便的实现一个字符串中某个字符的样式处理.我把我下面代码实现的功能步骤说一下:首先拼接两个字符串,然后给前前半部 ...
- iOS 学习 - 12.NSMutableAttributedString 计算高度
计算 NSMutableAttributedString 高度,必须要有两个属性 -(void)test{ UILabel *label = [[UILabel alloc]initWithFrame ...
- 新浪微博客户端(35)-使用NSMutableAttributedString实现多行文本的效果
DJComposeViewController.m import "DJComposeViewController.h" #import "DJAccountTool.h ...
- NSMutableAttributedString可变属性字符串的用法
适用于:当你想对一个字符串中的某几个字符更改颜色,字体... NSString *string = @"今日营养配餐提供热量1800千卡,需要饮食之外额外补充钙10mg,铁20mg,锌9.5 ...
随机推荐
- 尚学堂Spring视频教程(一):模拟Spring
Spring简单的说就是作为控制反转的容器,看这篇文章前需要先搞懂“控制反转和依赖注入“这个设计模式 我们先来模拟Spring,实现用户添加的功能,新建WEB项目”Spring_0100_Abstra ...
- 记录一下emacs在window下的配置过程
今天重装WIN7 64位新系统,装完发现emacs无法加载以前的插件了.网上搜一下才记起来,emacs默认读取的配置文件在c盘,在这个原始配置文件中还需要添加一些路径转换的语句才能转到用户自己的配置文 ...
- Excel with COM
COM excelApplication ; COM workBooks ; COM workSheets ; COM workSheet ; COM work ...
- 让VS 2010在调试字符串时,支持Json数据格式友好显示
阅读本文如果对Microsoft.VisualStudio.DebuggerVisualizers的用法不熟悉的,可以参考这篇文章.http://www.cnblogs.com/devil0153/a ...
- Asprise-OCR的使用
Asprise-OCR下载地址: http://asprise.com/product/ocr/download.php?lang=csharp 其中需要使用的3个dll是AspriseOCR.dll ...
- 两系统用asp.net forms 身份验证方式实现跨域登录信息共享
1.两个系统的 web.config 都配置为 forms 验证方式( system.web —> authentication 节点) 2.在两个系统的Web.config里配置相同的 sys ...
- Linux里的2>&1
我们在Linux下经常会碰到nohup command>/dev/null 2>&1 &这样形式的命令.首先我们把这条命令大概分解下首先就是一个nohup表示当前用户和系统 ...
- ffmpeg relocation error
在向imx6移植ffmpeg后,一般的编解码操作没有问题,但是当从摄像头录视频时, ffmpeg -f video4linux2 -s 640*480 -r 10 -i /dev/video0 tes ...
- items2 配色
cat ~/.bash_profile #enables colorin the terminal bash shell exportexport CLICOLOR=1 #sets up thecol ...
- jquery让滚动条跳到最底部
selector.scrollTop(50000); 添加一个最大的数值: 或者 公式:内容器的高度加上外层容器的padding,再减去外层容器的高度: var tableHeight = $(' ...