设置@一个人时字符串为蓝色
2015-03-31 17:00
92 查看
搜索某个子字符串在字符串中的位置
NSString *string1 = @"This is a string";
NSString *string2 = @"string";
NSRange range = [string1 rangeOfString:string2];
int location = range.location;
int leight = range.length;
NSString *astring = [[NSString alloc] initWithString:[NSString stringWithFormat:@"Location:%i,Leight:%i",location,leight]];
NSLog(@"astring:%@",astring);
[astring release];
设置同一个label中不同文字不同颜色
self.title = @"For iOS 6 & later";
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];
attrLabel.attributedText = str;
NSString *string1 = @"This is a string";
NSString *string2 = @"string";
NSRange range = [string1 rangeOfString:string2];
int location = range.location;
int leight = range.length;
NSString *astring = [[NSString alloc] initWithString:[NSString stringWithFormat:@"Location:%i,Leight:%i",location,leight]];
NSLog(@"astring:%@",astring);
[astring release];
设置同一个label中不同文字不同颜色
self.title = @"For iOS 6 & later";
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];
attrLabel.attributedText = str;
相关文章推荐
- 一步一步SharePoint 2007之十三:实现Form认证(3)——设置数据库连接字符串
- 运行时设置数据库连接字符串
- 怎样从ASP.NET 2.0中读取连接字符串的设置新增方法
- ACCESS在Web.config里设置连接字符串
- 一步一步SharePoint 2007之十三:实现Form认证(3)——设置数据库连接字符串
- Scott Mitchell 的ASP.NET 2.0数据教程之73:保护连接字符串及其它设置信息
- 怎样从ASP.NET 2.0中读取连接字符串的设置
- asp.net 设置字符串格式与string.Format的应用
- 不能设置桌面背景始终显示蓝色怎么办?
- 保护代码中的数据库连接字符串和其他敏感设置
- 各种连接字符串设置
- Webconfig中使用appSettings设置连接字符串(转)
- ASP.NET 2.0中连接字符串的设置
- 怎样从ASP.NET 2.0中读取连接字符串的设置
- web.config中数据库连接字符串设置
- Webconfig中使用appSettings设置连接字符串(转)
- ASP.NET 2.0中连接字符串的设置
- ASP.NET 2.0中连接字符串的设置
- C# 多种方法读取和设置连接字符串
- GridView 中设置某列,截取字符串加"..." 和 鼠标放上去字符全部显示