NSAttributedString编程
- (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编程的更多相关文章
- NSAttributedString 的21种属性 详解
原文链接:http://www.jianshu.com/p/09f54730feaa 先看看所有的Key NSFontAttributeName; //字体,value是UIFont对象 NSPara ...
- iOS项目开发之Socket编程
有一段时间没有认真总结和写博客了 前段时间找工作.进入工作阶段.比较少静下来认真总结,现在静下心来总结一下最近的一些心得 前言 AsyncSocket介绍 AsyncSocket详解 AsyncSoc ...
- iOS多线程编程指南
iOS多线程编程指南(拓展篇)(1) 一.Cocoa 在Cocoa上面使用多线程的指南包括以下这些: (1)不可改变的对象一般是线程安全的.一旦你创建了它们,你可以把这些对象在线程间安全的传递.另一方 ...
- 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代
2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...
- JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议
软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...
- 读书笔记:JavaScript DOM 编程艺术(第二版)
读完还是能学到很多的基础知识,这里记录下,方便回顾与及时查阅. 内容也有自己的一些补充. JavaScript DOM 编程艺术(第二版) 1.JavaScript简史 JavaScript由Nets ...
- [ 高并发]Java高并发编程系列第二篇--线程同步
高并发,听起来高大上的一个词汇,在身处于互联网潮的社会大趋势下,高并发赋予了更多的传奇色彩.首先,我们可以看到很多招聘中,会提到有高并发项目者优先.高并发,意味着,你的前雇主,有很大的业务层面的需求, ...
- C#异步编程(一)
异步编程简介 前言 本人学习.Net两年有余,是第一次写博客,虽然写的很认真,当毕竟是第一次,肯定会有很多不足之处, 希望大家照顾照顾新人,有错误之处可以指出来,我会虚心接受的. 何谓异步 与同步相对 ...
- UE4新手之编程指南
虚幻引擎4为程序员提供了两套工具集,可共同使用来加速开发的工作流程. 新的游戏类.Slate和Canvas用户接口元素以及编辑器功能可以使用C++语言来编写,并且在使用Visual Studio 或 ...
随机推荐
- postgresql 常规操作以及检查备份
一.建表时,复制源表的信息test=# test=# \d test.t1 Table "test.t1" Column | Type | Collation | Nullable ...
- Ubuntu16.04下将hadoop2.7.3源代码导入到eclipse neon中
0.为什么会有这篇: 这篇文章的目的在于帮助想学习hadoop源码的内容,却在导入的过程中出现了各种问题的人. 或许你一定找了很多博客都无果,那么不用担心,我和你一样,这也是这篇文章存在的意义,废话少 ...
- POJ 1442 Treap模板
// by SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using na ...
- 3、Collection接口中的功能概述
package cn.itcast_01; import java.util.ArrayList; import java.util.Collection; /** * 集合: * 由于我们使用的是面 ...
- GoogleMap 获取自己的数字证书API key的步骤
http://dreamylights.blog.51cto.com/1163218/1360759 1. 进入到Google APIs Console页面 https://code.google.c ...
- android 自定义空间 组合控件中 TextView 不支持drawableLeft属性
android 自定义空间 组合控件中 TextView 不支持drawableLeft属性.会报错Caused by: android.view.InflateException: Binary X ...
- Spring依赖注入:@Autowired,@Resource和@Inject区别与实现原理
一.spring依赖注入使用方式 @Autowired是spring框架提供的实现依赖注入的注解,主要支持在set方法,field,构造函数中完成bean注入,注入方式为通过类型查找bean,即byT ...
- JS 20180416课时训练
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【leecode】小练习(简单8题)
def twoSum(nums, target): """ 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[ ...
- HTML5新特性之文件和二进制数据的操作 Blob对象
HTML5新特性之文件和二进制数据的操作 1.Blob对象 2.FileList对象 3.File对象 4.FileReader 对象 5.URL对象