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. 洛谷 [P1995] 程序自动分析

    并查集+ 离散化 首先本题的数据范围很大,需要离散化, STL离散化代码: //dat是原数据,id是编号,sub是数据的副本 sort(sub + 1, sub + tot + 1); size = ...

  2. GridView选中,编辑,取消,删除代码

    原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] 2.GridView选中,编辑,取消,删除: 效果图: 后台代码:你可以使用sqlhelper,本文没用。代码如下 ...

  3. 转:关于bugfree的一些不得不说的事

    昨天公司说要做一个工作流程控制系统,经朋友建议,尝试使用禅道进行管理,自己试用了下,感觉非常不错.下午看朋友发的关于禅道和bugfree的恩恩怨怨,更加佩服禅道的项目主管. 原文链接:http://w ...

  4. Android SurfaceView与View

    SurfaceView介绍 SurfaceView是视图(View)的继承类,这个视图里面内嵌了一个专门用于绘制的Surface.你可以控制这个Surface的格式和尺寸,而SurfaceView控制 ...

  5. [OS X实用技巧]机器人应用:一键将图片转换为PNG/JPEG/TIFF

    转自:http://www.maczhi.com/archives/2842.html 按教程老出错....试验了后使用: - 取得指定Finder对象,其它不变,但运行后不会出错. OS X实用技巧 ...

  6. 小窥React360——用React创建360全景VR体验

    前言    混迹VR届的发烧友兼开发者们一定不要错过这款FaceBook推出的跨端VR开发框架——React360,称为360全景体验框架更为准确,因为其前身是FaceBook和Oculus2017年 ...

  7. IO重定向

    http://tldp.org/LDP/abs/html/io-redirection.html http://mp.weixin.qq.com/s/JMHDutEG4R0hEaXrYPmCGg 每个 ...

  8. SSD S.M.A.R.T

    经过多年HDD硬盘厂商的完善,S.M.A.R.T已经形成了一些标准,但对于SSD来说,大多数S.M.A.R.T都是自定义的,以至于每个厂商所提供的参数并不一致,但大体都会参考HDD S.M.A.R.T ...

  9. SQL2000数据库密码被替换,重置密码提示未能找到存储过程sp_password解决方案

    利用windows身份验证进入查询分析器后在master数据库下运行如下脚本: create procedure sp_password @old sysname = NULL, -- the old ...

  10. BUPT复试专题—中序遍历序列(2013)

    题目描述 给出一个序列,判断该序列是不是某二叉搜索树的中序遍历序列,如果是输出"Yes",否则输出"No".一颗带权二叉树是一颗二叉搜索树(二叉排序树),当且仅 ...