- (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. spy++ 句柄消息详解

    使用spy++捕获到的消息详解 主要是今天正好自己用到. 原来也有用过SPY++查看消息,然后自己SendMessage或者PostMessage 直接发送消息给目标程序.但是原来一用就有效果,今天要 ...

  2. POJ 2513 trie树+并查集判断无向图的欧拉路

    生无可恋 查RE查了一个多小时.. 原因是我N define的是250500 应该是500500!!!!!!!!! 身败名裂,已无颜面对众人.. 吐槽完了 我们来说思路... 思路: 判有向图能否形成 ...

  3. QlikSense系列(3)——QlikSense建立数据模型

    QlikSense管理数据在帮助中写的比较清楚 https://help.qlik.com/zh-CN/sense/3.1/Subsystems/Hub/Content/LoadData/load-d ...

  4. C#中的流_字节_字符_字符串之间的相互转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  5. Java基础之多线程简述

    首先,要辨析进程与线程的概念: 进程是程序执行的过程,它持有资源和线程,相对于程序本身而言具有动态性. 线程是系统中最小的执行单元,同一个进程中可能有多个线程,它们共享该进程持有的资源.线程的通信也称 ...

  6. vue2.0项目中使用Ueditor富文本编辑器应用中出现的问题

    1.如何设置config中的内容 readonly:true,//只读模式wordCount:false,//是否开启字数统计enableAutoSave: false,//自动保存功能 重点:ena ...

  7. [OpenWrt]安装mjpg-streamer

    安装mjpg-streamer 远程监控基本上是wifi小车的一个必备功能了.摄像头我用的是奥尼百脑通 D881,这个要100左右. 确认安装了以下软件: kmod-usb2 kmod-video-u ...

  8. 基于S3C2440数码相框

    [参考]韦东山 教学笔记 1. 程序框架1.1 触摸屏: 主按线程,通过socket发给显示进程 --------------------------- 封装事件:ts线程 按键线程 -------- ...

  9. js 获取 下拉框的值

    //错误 console.log($("#DictID").select.val()); //错误 console.log($("#DictID").selec ...

  10. jQuery节点操作方法大全

    1.append() 向每个匹配的元素内部追加内容 HTML代码: <p>我想说:</p> jQuery代码: $('p').append('<b>你好</b ...