CoreText的使用方法
- (void)draw {
CGContextRef context = UIGraphicsGetCurrentContext();
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:self.text] autorelease];
[attrString addAttribute:(NSString *)(kCTForegroundColorAttributeName) value:(id)self.strokeColor.CGColor range:NSMakeRange(, [self.text length])];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(, [attrString length]), self.path.CGPath, NULL);
CFRelease(framesetter);
//CFRelease(attrString);
if (frame) {
CGContextSaveGState(context);
// Core Text wants to draw our text upside-down! This flips it the
// right way.
CGContextTranslateCTM(context, , path.bounds.origin.y);
CGContextScaleCTM(context, , -);
CGContextTranslateCTM(context, , -(path.bounds.origin.y + path.bounds.size.height));
CTFrameDraw(frame, context);
CGContextRestoreGState(context);
CFRelease(frame);
}
}
首先获得当前的上下文
创建一个属性自字符串NSMutableAttributedString 并设置他的颜色以及其他属性
利用该属性字符串 创建一个CTFramesetterRef
再创建一个CTFrameRef
释放之前创建的CTFramesetterRef 对象framesetter
由于CoreText 是来自于Mac OS X的 它在绘图的时候 认为坐标轴是倒置的,所以在没ios中会产生倒置的效果,这里要转化以下才能正常显示
参考:http://www.cnblogs.com/bucengyongyou/archive/2012/09/14/2685797.html
CoreText的使用方法的更多相关文章
- 30、准确计算CoreText高度的方法
http://ios-iphone.diandian.com/post/2012-03-29/18389515 - (int)getAttributedStringHeightWithString:( ...
- 准确计算CoreText高度的方法:
- (int)getAttributedStringHeightWithString:(NSAttributedString *) string WidthValue:(int) width { ; ...
- CoreText实现图文混排
CoreText的介绍 Core Text 是基于 iOS 3.2+ 和 OSX 10.5+ 的一种能够对文本格式和文本布局进行精细控制的文本引擎.它良好的结合了 UIKit 和 Core Graph ...
- 初识 TextKit
iOS 7 的发布给开发者的案头带来了很多新工具.其中一个就是 TextKit.TextKit 由许多新的 UIKit 类组成,顾名思义,这些类就是用来处理文本的.在这里,我们将介绍 TextKit ...
- ios基础知识
1获取系统语言设置 NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *languages = ...
- iOS 基础知识
1获取系统语言设置 NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *languages = ...
- iOS富文本组件的实现—DTCoreText源码解析 渲染篇
本文转载至 http://blog.cnbang.net/tech/2729/ 上一篇介绍了DTCoreText怎样把HTML+CSS解析转换成NSAttributeString,本篇接着看看怎样把N ...
- iOS 7系列译文:认识 TextKit
OS 7:终于来了,TextKit. 功能 所以咱们到了.iOS7 带着 TextKit 登陆了.咱们看看它可以做什么!深入之前,我还想提一下,严格来说,这些事情中的大部分以前都可以做.如果你 ...
- iOS 7 认识 TextKit
本文由 伯乐在线 - 和谐老约翰 翻译自 Max Seelemann.欢迎加入技术翻译小组.转载请参见文章末尾处的要求. iOS7 的发布给开发者的案头带来了很多新工具.其中一个就是 TextKit( ...
随机推荐
- [Javascript] Understanding the .constructor property on JavaScript Objects
Constructor functions hold an interesting purpose in JavaScript. Unlike in classical languages, they ...
- Leetcode--easy系列10
#205 Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are ...
- java数据库连接池技术简单使用
JDBCDemo.java: package com.itheima.jdbc; import java.sql.Connection; import java.sql.PreparedStateme ...
- MySQL存储结构的使用
前言 今天公司老大让我做一个MySQL的调研工作,是关于MySQL的存储结构的使用.这里我会通过3个样例来介绍一下MySQL中存储结构的使用过程,以及一些须要注意的点. 笔者环境 系统:Windows ...
- Handlebars.js 中文文档
Home » 前端 » Handlebars.js 中文文档 Handlebars.js 中文文档 Posted in 前端 By KeenWon On 2014年4月3日 Views: ...
- Android 常用Shell命令
1.查询模拟器/设备实例 adb devices 2.从模拟器/设备中拷入或拷出文件(默认拷贝在执行目录) 从模拟器或者设备中复制文件或目录,使用(如下命): adb pull <remote& ...
- 堆排序C++实现
//heap sort //堆排序能够分为两个过程.其一是建堆.其二是出堆 //堆是一种全然二叉树,所以它能够用数组进行存储. //堆可分为最大堆和最小堆.最大堆指任一节点的值都大于其左右孩子节点的值 ...
- Tomcat 安装错误
安装tomcat时,遇到"failed to install tomcat6 service check your settings and permissions"的问题 安装时 ...
- 设计模式-(17)策略模式 (swift版)
一,概念: 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使他们可以相互替换,让算法独立于使用它的客户而独立变化. 二,使用场景 1.针对同一类型问题的多种处理方式,仅仅是具体行为有差别时: ...
- linux系统编程之进程(七):system()函数使用【转】
本文转载自:http://www.cnblogs.com/mickole/p/3187974.html 一,system()理解 功能:system()函数调用“/bin/sh -c command” ...