- (void)viewDidLoad

{

    [super viewDidLoad];



    

    NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc] initWithString:@"測试富文本显示"] autorelease];

    //为全部文本设置字体

    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:24.0] range:NSMakeRange(0, [attributedString length])];

    //将“測试”两字字体颜色设置为蓝色

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

    //将“富文本”三个字字体颜色设置为红色

    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 3)];



    self.label = [[[UILabel alloc] init] autorelease];

    self.label.frame = CGRectMake(10, 100, 300, 30);

    self.label.attributedText = attributedString;

    [self.view addSubview:self.label];

    

    UIFont *font = [UIFont fontWithName:@"Palatino-Roman" size:14.0];

    NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font

                                                                forKey:NSFontAttributeName];

    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"用DIC显示文字"

                                                                     attributes:attrsDictionary];

    UILabel *labTwo = [[UILabel alloc] initWithFrame:CGRectMake(10, 150, 300, 30)];

    labTwo.attributedText = attrString;

    [self.view addSubview:labTwo];

    [labTwo release];

    [attrString release];

    

    UIFont *dicFont = [UIFont boldSystemFontOfSize:20];

    UIColor *foregroundColor = [UIColor blueColor];

    NSNumber *underline = [NSNumber numberWithInt:NSUnderlineStyleSingle];  // 下划线

    

    NSShadow *shadow = [[NSShadow alloc] init];

    shadow.shadowBlurRadius = 5;  // 模糊度

    shadow.shadowColor = [UIColor blackColor];

    shadow.shadowOffset = CGSizeMake(1, 3);

    

    NSDictionary *attrsDic = @{NSForegroundColorAttributeName: foregroundColor,

                               NSUnderlineStyleAttributeName: underline,

                               NSFontAttributeName:dicFont,

                               //NSStrokeColorAttributeName:[UIColor redColor], // 绘制空心字颜色

                               //NSStrokeWidthAttributeName:@3,                  // 默觉得 0。即不改变。正数仅仅改变描边宽度。负数同一时候改变文字的描边和填充宽度。

比如,对于常见的空心字,这个值通常为3.0。

                               NSShadowAttributeName:shadow,

                               NSObliquenessAttributeName:@0.5,   // 设置字体倾斜度

                               };

    

    NSAttributedString *attributedString_str_atts = [[NSAttributedString alloc] initWithString:@"http://www.baidu.com" attributes:attrsDic];

    // NSLog(@"%@", attributedString_str_atts);

    UILabel *labThree = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, 300, 30)];

    labThree.attributedText = attributedString_str_atts;

    [self.view addSubview:labThree];

    [attributedString_str_atts release];

    [labThree release];

    

    UIFont *txtFont = [UIFont boldSystemFontOfSize:30];

    NSDictionary *attDic = @{NSFontAttributeName:txtFont,

                             NSObliquenessAttributeName:@0.5,

                             };

    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:@"測试显示" attributes:attDic];

    

    

    UILabel *labFour = [[UILabel alloc] initWithFrame:CGRectMake(10, 250, 300, 50)];

    labFour.attributedText = attribute;

    [self.view addSubview:labFour];

    [attribute release];

    [labFour release];

}

NSAttributedString编程的更多相关文章

  1. NSAttributedString 的21种属性 详解

    原文链接:http://www.jianshu.com/p/09f54730feaa 先看看所有的Key NSFontAttributeName; //字体,value是UIFont对象 NSPara ...

  2. iOS项目开发之Socket编程

    有一段时间没有认真总结和写博客了 前段时间找工作.进入工作阶段.比较少静下来认真总结,现在静下心来总结一下最近的一些心得 前言 AsyncSocket介绍 AsyncSocket详解 AsyncSoc ...

  3. iOS多线程编程指南

    iOS多线程编程指南(拓展篇)(1) 一.Cocoa 在Cocoa上面使用多线程的指南包括以下这些: (1)不可改变的对象一般是线程安全的.一旦你创建了它们,你可以把这些对象在线程间安全的传递.另一方 ...

  4. 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代

    2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...

  5. JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议

    软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...

  6. 读书笔记:JavaScript DOM 编程艺术(第二版)

    读完还是能学到很多的基础知识,这里记录下,方便回顾与及时查阅. 内容也有自己的一些补充. JavaScript DOM 编程艺术(第二版) 1.JavaScript简史 JavaScript由Nets ...

  7. [ 高并发]Java高并发编程系列第二篇--线程同步

    高并发,听起来高大上的一个词汇,在身处于互联网潮的社会大趋势下,高并发赋予了更多的传奇色彩.首先,我们可以看到很多招聘中,会提到有高并发项目者优先.高并发,意味着,你的前雇主,有很大的业务层面的需求, ...

  8. C#异步编程(一)

    异步编程简介 前言 本人学习.Net两年有余,是第一次写博客,虽然写的很认真,当毕竟是第一次,肯定会有很多不足之处, 希望大家照顾照顾新人,有错误之处可以指出来,我会虚心接受的. 何谓异步 与同步相对 ...

  9. UE4新手之编程指南

    虚幻引擎4为程序员提供了两套工具集,可共同使用来加速开发的工作流程. 新的游戏类.Slate和Canvas用户接口元素以及编辑器功能可以使用C++语言来编写,并且在使用Visual Studio 或 ...

随机推荐

  1. Centos7中 文件大小排序

    centos7中根据文件大小排序以及jenkins配置每周删除一次jobs日志信息 https://blog.csdn.net/u013066244/article/details/70232050

  2. linux下使用bcp备份sybase数据

    命令|数据库名|表名|导出到|文件名|格式|sybase服务名|数据库登录名 |字符集 bcp dbname..tablename out filename -n -Sgfdmhk -UISISMan ...

  3. React安装 脚手架create-react-app安装步骤及问题

    create-react-app 是来自于 Facebook的脚手架,通过该命令我们无需配置就能快速构建 React 开发环境. 安装步骤: 1.先装脚手架     PS:第一次装直接在打开CMD默认 ...

  4. 企业级Spring应用的搭建

    本次博客将要对SpringMVC做简单的介绍以及环境的搭建: 概述 Spring 框架是一个开源的平台,属于设计层面框架,整个系统面向接口,是分层的JavaSE/EE开源框架,用于解决复杂的企业应用开 ...

  5. VS Code中编写html(4) 标签的宽高颜色背景设置

    1  <!+Tab键--> <!--有两个div标签时,分别设置style,有两种方法--> <div id="div1">第一个div标签:& ...

  6. 算法46----移除K位数字

    一.题目:移除K位数字 给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小. 注意: num 的长度小于 10002 且 ≥ k. num 不会包含任何前导零. 示 ...

  7. twemproxy 安装与配置

    转自:http://blog.csdn.net/u011183653/article/details/21240749 说到twemproxy就不得不说要一下redis,这是因为twemproxy是为 ...

  8. mysql数据库增量恢复

    mysqldump -uroot -p -B discuzx -F -x --master-data=2 --events|gzip >/root/discuzx.sql.gz 写入数据 删除数 ...

  9. redis helloworld

    一.启动 redis 服务 [root@MyLinux bin]# ./redis-server redis.conf 二.使用客户端连接服务 [root@MyLinux bin]# ./redis- ...

  10. jQuery(表单选择器)