UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 300, 30)];

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"set background color with button"];

[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,2)];

[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];

[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];

[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:17.0] range:NSMakeRange(0, 5)];

[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17.0] range:NSMakeRange(6, 12)];

[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:17.0] range:NSMakeRange(19, 6)];

Label.attributedText = string;

[self.view addSubview:Label];

   效果图 :  set background color with button

iOS在一个label中显示不同颜色的字体的更多相关文章

  1. 解决alert在ios版微信中显示url的问题(重写alert)

    为了解决alert在ios版微信中显示url的问题 window.alert = function(name){ var iframe = document.createElement("I ...

  2. 小技巧,如何在Label中显示图片

    这个需求其实是有的,比如QQ聊天界面里面发送的信息,可以用label来显示文字(也可以用button显示),但是有时候用户可能会发送图片.如果能让Label遇到文字就显示文字,遇到图片就显示图片就好了 ...

  3. iOS开发实现Label中多颜色多字体

     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 100, 300, 30)]; label.textColor = wor ...

  4. iOS 如何在Label中显示html的文本

    if (self.messageModel) { NSString * htmlString = self.messageModel.contentText; NSAttributedString * ...

  5. label显示不同颜色的字体

    NSString *contentSrt = [NSString stringWithFormat:@"%@ (%@)",categoryModel.categoryName, c ...

  6. iOS上用FTGL显示定制Truetype字体碰到的问题

    没想到这个问题搞了快2个月时间:当然跟我只是断断续续地工作有关. FTGL是freetype的opengl实现.我接触FTGL最初只是为了练习OpenGL,写几个简单的游戏app.开始试了试FTGL觉 ...

  7. 在Label中显示一段文字

    Let’s create a new Xamarin.Forms PCL solution, named Greetings, using the same process described abo ...

  8. 在一个Label上设置多种颜色字体

    #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL ...

  9. Python3 tkinter基础 LabelFrame StringVar 单击按钮,Label中显示的文字更换

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. 【Codeforces Round #505 (Div. 1 + Div. 2) 】

    A:https://www.cnblogs.com/myx12345/p/9843966.html B: C:https://www.cnblogs.com/myx12345/p/9844084.ht ...

  2. ftrace用法

    ftrace官方文档在kernel/Documentation/trace/ftrace.txt文件中. 使用ftrace接口之前,如果系统没有自动挂载debugfs文件系统,则要先手动挂载. # m ...

  3. substring用法

    字符串截取,substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串. substring(int beginIndex, int endIndex) 返回一 ...

  4. Struts2牛逼的拦截器,卧槽这才是最牛的核心!

    struts 拦截器 一 拦截器简介及简单的拦截器实例 Struts2拦截器是在访问某个Action或者Action的某个方法,在字段前或者之后实施拦截,并且Struts2拦截器是可以插拔的,拦截器是 ...

  5. Oracle 12c agent install for linux

    安装Agent代理 在EM11g时,agent安装是通过在被监制主机端下载agent代理并安装,在EM12c版本号上,能够在EM12c服务端.通过"推送"的方式把agent代理在远 ...

  6. [转]Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案

    原文地址:http://www.cnblogs.com/gb2013/archive/2013/03/05/SecurityEnhancementsInTheCRT.html 在VS 2012 中编译 ...

  7. C++类型的转换

    C风格转换是“万能的转换”,但需要程序员把握转换的安全性,编译器无能为力:static_cast最接近于C风格转换,但在无关类指针转换时,编译器会报错,提升了安全性:dynamic_cast要求转换类 ...

  8. Python源代码--整数对象(PyIntObject)的内存池

    [背景] 原文链接:http://blog.csdn.net/ordeder/article/details/25343633 Python整数对象是不可变对象,什么意思呢?比如运行例如以下pytho ...

  9. Oracle RAC cache fusion原理測试

    Oracle RAC cache fusion是RAC最核心的工作机制.他把全部实例的SGA虚拟成一个大的SGA区,每当不同的实例请求同样的数据块,这个数据块就须要在实例间进行传递. 那究竟什么时候传 ...

  10. Linux启动过程笔记

    Linux启动过程 1.启动流程(BIOS->MBR:Boot Code->引导GRUB->载入内核->运行init->runlevel) 2./boot/grub/下有 ...