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 667C Reberland Linguistics【DFS】

    一道卡题意的题. 题目链接: http://codeforces.com/problemset/problem/667/C 题意: 一个串可以看成一个长度大于4的根,加上其后面的若干个相邻(in a ...

  2. centos 关于防火墙的命令

    CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...

  3. MySQL的LOOP, LEAVE 和ITERATE语句(类似Continue、Break的写法)

    和REPEAT和while语句不同,LOOP.LEAVE.ITERATE更像其他编程语言中的goto语句. LOOP要设定一个label指定循环的开始位置,而LEAVE则像其他语言中的Break会离开 ...

  4. Google的JSON风格指南

    官网:https://google.github.io/styleguide/jsoncstyleguide.xml 中文版:https://github.com/darcyliu/google-st ...

  5. Go -- 中开启gctrace

    godebug是一个跨平台的Go程序调试工具,传统的编译型语言调试器使用底层系统调用并读取二进制文件用于调试各类符号.使用起来很麻烦而且很难移植. godebug使用不同的方法,直接把源码作为目标程序 ...

  6. 简单、强大的swig.js

    Swig.js A simple, powerful, and extendable JavaScript Template Engine. 简单概括:JS模板引擎. Why to use 根据路劲渲 ...

  7. 在canvas上面拖拽对象。

    原文:https://html5.litten.com/how-to-drag-and-drop-on-an-html5-canvas/ 下面作者的原始的版本会抖动一下(鼠标刚点下去的时候,位置会发生 ...

  8. JS创建对象几种不同方法具体解释

    1.工厂模式 弊端:没有解决对象的识别问题,即怎么知道一个对象的类型. 2.构造函数模式 与工厂模式相比: 1.没有显式的创建对象 2.直接将属性和方法赋给了this对象 3.没有return语句 要 ...

  9. Collection接口和Collections类的简单区别和讲解

    这里仅仅进行一些简单的比较,如果你想要更加详细的信息话,请自己百度. 1.Collection: 是集合类的上层接口.本身是一个Interface,里面包含了一些集合的基本操作. Collection ...

  10. Golang之bytes.buffer

    bytes.buffer是一个缓冲byte类型的缓冲器存放着都是byte Buffer 是 bytes 包中的一个 type Buffer struct{-} A buffer is a variab ...