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 或 ...
随机推荐
- js重定向
在现行的网站应用中URL重定向的应用有很多: 404页面处理.网址改变(t.sina转到weibo.com).多个网站地址(如:http://www.google.com/ .www.g.cn )等: ...
- 创建异步对象XHR的兼容写法、get、post上传数据的方式
兼容ie7以下,创建异步对象的函数 function creatXHR(){ if(typeof XMLHttpRequest != "undefined"){ return ne ...
- (转)webpack从零开始第6课:在Vue开发中使用webpack
vue官方已经写好一个vue-webpack模板vue_cli,原本自己写一个,发现官方写得已经够好了,自己写显得有点多余,但为了让大家熟悉webpack,决定还是一步一步从0开始写,但源文件就直接拷 ...
- hdu 2489 dfs枚举组合情况+最小生成树
大家都说,搜索是算法的基础.今天最这题就有体会了.在n个顶点里选择m个顶点,求最小生成树.用到了深搜的回溯.所有情况都能枚举. #include<iostream> #include< ...
- 杭电 1021 Fibonacci Again
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1021 解题思路:根据之前发现斐波那契数列的规律,即为f(n)能被3整除当且仅当n能被4整除. 于是联想 ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(2)- 使用EasyUI的树控件构建Web界面
http://www.cnblogs.com/wuhuacong/p/3669575.html 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开 ...
- 谈谈网页中的ajax
一个页面上有很多的ajax请求,这样的页面右键查看源文件是没法看到全部的html.事实上,这种网页也是从正常的html页面改造过来的,常用的一个场景是,同一个区域大量循环,在动态页面里(比如jsp等) ...
- Flask框架函数
title: flask学习笔记 subtitle: 1. flask框架函数 date: 2018-12-14 10:17:28 --- Flask学习 学习Miguel Grinberg的2017 ...
- mysql 读写分离 ,mysql_proxy实现
下载安装mysql_proxy: 解压后, 该目录包含已经编译好的二进制文件 . 1: 利用mysql_proxy实现负载均衡 执行mysql_proxy ./mysql-proxy-path/bin ...
- [tyvj-1071]LCIS 动态规划
LCIS模板 #include <cstdio> #include <cstring> #include <iostream> using namespace st ...