在一个Label上设置多种颜色字体
#import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
// 设置多属性字符串
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
// 设置蓝色字体,范围(0, 5),其中空格也算一个占位符
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(, )];
// 设置红色字体,范围(6, 12),其中空格也算一个占位符
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(, )];
// 设置红色字体,范围(13, 6),其中空格也算一个占位符
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(, )]; label.attributedText = str; [self.window addSubview:label];
[self.window makeKeyAndVisible];
return YES;
} @end
在一个Label上设置多种颜色字体的更多相关文章
- android 一个TextView设置多种颜色
时候一个文本框为了强调内容需要显示不同颜色,用以下代码可以轻松实现 方法一:(适用于颜色变化多的情况) //为文本框设置多种颜色 textView=(TextView)findViewById(R ...
- iOS一段文字设置多种颜色格式
调用 [self fuwenbenLabel:contentLabel FontNumber:[UIFont systemFontOfSize:] AndRange:NSMakeRange(, ) A ...
- iOS在一个label中显示不同颜色的字体
UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 300, 30)]; NSMutableAttributedSt ...
- idea软件上设置爱彼迎字体
- UILable:显示多种颜色的方法
借用别人封装好的类库,用来显示同一个UILable上的多种颜色的字. 类库可以直接在次博客中下载,下载后别忘留言哦. 类库使用:主要用了CoreText里面的东西,所以在使用类库之前需要引用CoreT ...
- asp.net在配置文件里设置多种编码方式的研究
我们在做asp.net的程序时,在根目录下肯定会有一个web.config的文件, 有点开发经验的可能都知道,它是配置程序的全局信息的地方, 当然了,也可以在这里做更多的事情,下面我们来研究一下 ,如 ...
- 设置label的文字,一行多种颜色
调用 [self fuwenbenLabel:contentLabel FontNumber:[UIFont systemFontOfSize:] AndRange:NSMakeRange(, ) A ...
- NSString -- UILabel中字体有多种颜色,字符串自动计算高度/换行
一:UILabel中字体有多种颜色 UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(, , , ); label.b ...
- TextView的一些高级应用(自定义字体、显示多种颜色、添加阴影)
1. 自定义字体可以使用setTypeface(Typeface)方法来设置文本框内文本的字体,而android的Typeface又使用TTF字体文件来设置字体所以,我们可以在程序中放入TTF字 ...
随机推荐
- 数据库连接jdbc理解
1.突然在想,既然数据库中有很多数据库,不同的database,在使用数据库时候,要指定使用的哪个数据库,用use database命令,指定特定数据库. 2.那java代码中,直接jdbc,直接st ...
- jquery格式化时间戳 2011-01-01
/* * 时间戳转换日期 * @param <int> unixTime 待时间戳(秒) ...
- /etc/hosts.conf
一 作用 指定如何解析主机域名.可设置网络安全. 二 参数说明 默认情况,/etc/hosts.conf 文件有如下内容—— order hosts,bind ...
- try...except 抛出错误
- Shell-bash中特殊字符汇总[转]
转自http://www.linuxidc.com/Linux/2015-08/121217.htm 首先举例一个bash脚本 #!/bin/bash file=$1 files=`find / -n ...
- Introduction to Structured Data
https://developers.google.com/search/docs/guides/intro-structured-data Structured data refers to kin ...
- 灰度图像 Grayscale Binary_image
https://en.wikipedia.org/wiki/Grayscale https://zh.wikipedia.org/wiki/灰度图像 In photography and comput ...
- Ngrok 内网穿透利器
Ngrok是什么 Ngrok 是一个反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道.Ngrok 可捕获和分析所有通道上的流量,便于后期分析和重放 为什么要使用Ngrok ...
- css层叠选择
首先声明一下CSS三大特性——继承.优先级和层叠.继承即子类元素继承父类的样式,比如font-size,font-weight等f开头的css样式以及text-align,text-indent等t开 ...
- net use
net use * \\ipaddr\share "password" /user:"username" /persistent:yes 在运行中输入“\\”+ ...