Ios 在一个标签上有不同的颜色和字体大小
我最近正在学习iOS开发,我想知道是否有可能有一个不同大小、不同字体和不同颜色的标签,例如 用户名(蓝色、粗体和大字体)正在观看行尸走肉(红色、粗体和中字体)在xxxx站点(蓝色、粗体和大字体)Ios 在一个标签上有不同的颜色和字体大小,ios,uilabel,Ios,Uilabel,我最近正在学习iOS开发,我想知道是否有可能有一个不同大小、不同字体和不同颜色的标签,例如 用户名(蓝色、粗体和大字体)正在观看行尸走肉(红色、粗体和中字体)在xxxx站点(蓝色、粗体和大字体) 谢谢 在您的情况下,您需要使用 同时,这也是找到任何自定义控制器的最佳站点,在您的情况下再见,源代码很好:在您的情况下,您需要使用 这也是找到任何自定义控制器的最佳站点,再见,在您的情况下,源代码很好:有两种方法可以做到这一点 xib文件或故事板 转到标签,选择“属性”而不是“普通” 那你想干什么就干
谢谢 在您的情况下,您需要使用
同时,这也是找到任何自定义控制器的最佳站点,在您的情况下再见,源代码很好:在您的情况下,您需要使用
这也是找到任何自定义控制器的最佳站点,再见,在您的情况下,源代码很好:有两种方法可以做到这一点
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:@"user name is watching walking dead on xxx site"];
[attributedString addAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:
NSFontAttributeName, [UIFont fontWithName:@"WHATEVER FONT" size:FONT_SIZE_HERE],
NSForegroundColorAttributeName, [UIColor blueColor],
nil]
range:NSMakeRange(0, 9)];//9 is the length of "user name"
[attributedString addAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:
NSFontAttributeName, [UIFont fontWithName:@"WHATEVER FONT" size:FONT_SIZE_HERE],
NSForegroundColorAttributeName, [UIColor blueColor],
nil]
range:NSMakeRange(22, 12)];//22 is the start index of "Walking dead"
//and 12 is the length of "Walking dead"
//you got the idea, same way to do the xxx site.
//Check a file called "NSAttributedString.h"
//you will find even more options there
希望这有帮助有两种方法
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:@"user name is watching walking dead on xxx site"];
[attributedString addAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:
NSFontAttributeName, [UIFont fontWithName:@"WHATEVER FONT" size:FONT_SIZE_HERE],
NSForegroundColorAttributeName, [UIColor blueColor],
nil]
range:NSMakeRange(0, 9)];//9 is the length of "user name"
[attributedString addAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:
NSFontAttributeName, [UIFont fontWithName:@"WHATEVER FONT" size:FONT_SIZE_HERE],
NSForegroundColorAttributeName, [UIColor blueColor],
nil]
range:NSMakeRange(22, 12)];//22 is the start index of "Walking dead"
//and 12 is the length of "Walking dead"
//you got the idea, same way to do the xxx site.
//Check a file called "NSAttributedString.h"
//you will find even more options there
希望这对您使用NSAttributedString有所帮助。。在发布之前,请查看相关问题。或者先做一些搜索。检查这个:我想这就是你要找的NSAttributedString。如果你想单独使用iOS7,请查看TextKit。它给你很大的能力。为此,您必须使用NSAttributedString。在发布之前,请先看一下向您展示的相关问题。或者先做一些搜索。检查这个:我想这就是你要找的NSAttributedString。如果你想单独使用iOS7,请查看TextKit。它给你很大的能力。