- 浏览: 676592 次
- 性别:
- 来自: 深圳
最新评论
-
fingerplay:
请问一下,第一份,逻辑树,就是代码里可以操纵的,例如更改lay ...
UIView与CALayer -
ok_lyc:
分享到哪里去了
iPhoneUIFont各种字体 -
lliiqiang:
我的个人理解:wait方法是在java虚拟机层面上在获取对象锁 ...
JAVA多线程同步wait、notify、synchronized -
milixw:
谢谢分享,就在找这个
iphone 推送通知 java 实现 -
wsqwsq000:
你的log4j包不行,上网搜一下:log4j-1.2.16.j ...
iphone 推送通知 java 实现
首先,进行创建一个UIView的子类,并实现如下代码: - (void)drawRect:(CGRect)rect { //创建要输出的字符串 //创建AttributeString //创建字体以及字体大小 //添加字体 目标字符串从下标0开始到字符串结尾 //添加字体 目标字符串从下标0开始,截止到4个单位的长度 //添加字体 目标字符串从下标6开始,截止到5个单位长度 //添加字体 目标字符串从下标109开始,截止到9个单位长度 //添加字体 目标字符串从下标223开始,截止到6个单位长度 //添加颜色,目标字符串从下标0开始,截止到4个单位长度 //添加过程同上 [string addAttribute:(id)kCTForegroundColorAttributeName [string addAttribute:(id)kCTForegroundColorAttributeName //创建文本对齐方式 //创建文本行间距 //创建样式数组 //设置样式 //给字符串添加样式attribute // layout master CGMutablePathRef leftColumnPath = CGPathCreateMutable(); CTFrameRef leftFrame = CTFramesetterCreateFrame(framesetter, // flip the coordinate system // draw // cleanup CGPathRelease(leftColumnPath); }
// Drawing code.
NSString *longText = @”袁唯来来 Lorem ipsum dolor sit amet, Before the iPad was released you had basically two ways how to get text on screen. Either you would stick with UILabel or UITextView provided by UIKit or if you felt hard-core you would draw the text yourself on the Quartz level incurring all the headaches induced by having to mentally switch between Objective-C and C API functions.\
As of iOS 3.2 we gained a third alternative in Core Text promising full control over styles, thread safety and performance. However for most of my apps I did not want to break 3.x compatibility and so I procrastinated looking at this powerful new API. Apps running only on iPads could have made use of Core Text from day 1, but to me it made more sense supporting iPad via hybrid apps where the iPhone part would still be backwards compatible.\
Now as the year has turned the adoption of 4.x on all iOS platforms is ever more accelerating. Many new iPads where found under the Christmas tree and by now even the most stubborn people (read needing 3.x for jailbreaking and sim-unlocking) have little reason to stick with 3.x. Thus we have almost no incentive left to stick with 3.x compatibility. Yay!”;
NSMutableAttributedString *string = [[NSMutableAttributedString alloc]
initWithString:longText];
CTFontRef helvetica = CTFontCreateWithName(CFSTR(”Helvetica”), 14.0, NULL);
CTFontRef helveticaBold = CTFontCreateWithName(CFSTR(”Helvetica-Bold”), 14.0, NULL);
[string addAttribute:(id)kCTFontAttributeName
value:(id)helvetica
range:NSMakeRange(0, [string length])];
[string addAttribute:(id)kCTFontAttributeName
value:(id)helveticaBold
range:NSMakeRange(0, 4)];
[string addAttribute:(id)kCTFontAttributeName
value:(id)helveticaBold
range:NSMakeRange(6, 5)];
[string addAttribute:(id)kCTFontAttributeName
value:(id)helveticaBold
range:NSMakeRange(109, 9)];
[string addAttribute:(id)kCTFontAttributeName
value:(id)helveticaBold
range:NSMakeRange(223, 6)];
[string addAttribute:(id)kCTForegroundColorAttributeName
value:(id)[UIColor blueColor].CGColor
range:NSMakeRange(0, 4)];
[string addAttribute:(id)kCTForegroundColorAttributeName
value:(id)[UIColor redColor].CGColor
range:NSMakeRange(18, 3)];
value:(id)[UIColor greenColor].CGColor
range:NSMakeRange(657, 6)];
value:(id)[UIColor blueColor].CGColor
range:NSMakeRange(153, 6)];
CTTextAlignment alignment = kCTLeftTextAlignment;//左对齐 kCTRightTextAlignment为右对齐
CTParagraphStyleSetting alignmentStyle;
alignmentStyle.spec=kCTParagraphStyleSpecifierAlignment;//指定为对齐属性
alignmentStyle.valueSize=sizeof(alignment);
alignmentStyle.value=&alignment;
CGFloat lineSpace=5.0f;//间距数据
CTParagraphStyleSetting lineSpaceStyle;
lineSpaceStyle.spec=kCTParagraphStyleSpecifierLineSpacing;//指定为行间距属性
lineSpaceStyle.valueSize=sizeof(lineSpace);
lineSpaceStyle.value=&lineSpace;
CTParagraphStyleSetting settings[]={
alignmentStyle,lineSpaceStyle
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, sizeof(settings));
[string addAttribute:(id)kCTParagraphStyleAttributeName
value:(id)paragraphStyle
range:NSMakeRange(0, [string length])];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(
(CFAttributedStringRef)string);
CGPathAddRect(leftColumnPath, NULL,
CGRectMake(0, 0,
self.bounds.size.width,
self.bounds.size.height));
CFRangeMake(0, 0),
leftColumnPath, NULL);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CTFrameDraw(leftFrame, context);
CFRelease(framesetter);
CFRelease(helvetica);
CFRelease(helveticaBold);
[string release];
UIGraphicsPushContext(context);
发表评论
-
iphone开发如何后台播放音频
2012-12-25 14:38 1563<!--?xml version="1.0&q ... -
iPhone开发中使用AVAudioPlayer出现内存泄漏的解决办法
2012-12-25 11:53 3349最近在使用AVAudioPlayer播放音频时,发现 ... -
dispatch多线程
2012-10-31 20:45 1460#define kBgQueue dispat ... -
iPhone开发使用数组排序
2012-10-30 19:18 1791我们以数组的排序为例(也许NSSortDes ... -
用containsObject判断是否存在的问题
2012-10-16 15:37 4566在NSArray或NSMutableArray中想使用c ... -
用NSZombieEnabled解决恼人的EXC_BAD_ACCESS错误
2012-09-17 10:30 1382转载自:http://longtimenoc.com/a ... -
使用xib加载视图后,在dealloc中crash
2012-09-08 11:20 1770最近遇到个问题,就是使用xib加载视图后,经常会 ... -
iPhone中如何获取当前输入法
2012-09-06 16:28 1702如题,在iPhone开发中,我们如何获取当前的输入 ... -
objectForKey和valueForKey的区别
2012-08-24 17:23 2167valueforkey和objectforkey区别 ... -
粒子发射系统中的CAEmitterLayer
2012-08-22 16:00 2522简介:CAEmitterLayer提供了一个基于 ... -
iPhone开发使用UILineBreakMode不精确
2012-07-26 12:02 1553一开始用UILineBre ... -
Xcode方法提示不显示的解决办法
2012-07-24 09:45 1616Xcode方法提示显示的不正确,只显示方法 ... -
NSArray的排序功能sortedArrayUsingSelector
2012-07-18 17:54 2234- (NSArray *)sortedArrayUs ... -
iPhoneUIFont各种字体
2012-07-24 09:45 1566苹果开发者们想在应用中使用不同字体的话,往往会发现 ... -
iPhone使用ASIHTTPRequest请求时,发送了2次请求
2012-07-24 09:45 2557前段时间用到ASIHTTPRequest做请求时, ... -
iPhone开发调用新浪微博OAuth2.0
2012-06-05 02:30 3104就像题目说的,这次的小项目是做一个新浪微博的客 ... -
Iphone cover flow 开源实现
2012-06-04 00:04 891tapkulibrary-CloverFlow ... -
ASIHTTPRequest下载示例(支持断点续传)
2012-07-24 09:45 1598在工程中,我们会常常遇到需要下载的程序,比 ... -
ASIHTTPRequest类库简介和使用说明
2012-07-24 09:45 1698文章转载自:http: ... -
NSUserDefaults 用户偏好设定保存自定义类(序列化)
2012-04-17 23:30 0NSUserDefaults 用户偏好设定保存 ...
相关推荐
CoreText
iOS coreText的demo
coretext图元绘制,路径绘制。能够绘制路径
使用CoreText实现电子书阅读效果(带翻页) 本项目为Demo,供大家参考电子书阅读 + 翻到下一页效果的实现
coreText 4-29 CoreText的使用
学会使用CoreText会帮助提升一些性能上的问题
基于CoreText的图文混排,需要加入CoreText库
详细 中文化 国外的一篇给力教程!! 从基础学起不错
可用于富文本Coretext ,正则匹配点击,@XX 表情 # # 的实现!
iOS 实现图文混排 coretextdemo
利用coreText实现图文混排 类似H5的新闻界面
coretext学习的基本代码,包括图文混编和文字链接
一篇文章里面的每个字符都应该有一个对应的 position 的,如果图片的位置是不确定的,那么应该有一个图片管理器,记录着图片ID和该图片对应的在文章中的 position 。 当排文字的时候,生成TextView,在排版过程中...
今天研究了CoreText,写了此demo,适合初学者看看。
swift 写的coretext 富文本的实现 可以实现点击 @somebody https
coreText简单的demo,实现文字和图片的排列
根据CoreText框架 实现富文本显示 颜色 字号 字体 的多变显示
IOS CoreText.图文混排,暂不支持图片点击。
CoreText是C API。 这个库是一组包装器和扩展,使使用Swift变得很方便。 CoreTextSwift Swifty CoreText API。 CoreText是C API。 这个库是一组包装器和扩展,使使用Swift变得很方便。 在当前图形上下文保护中绘制...
UICoreTextView-CoreText文字渲染ios源代码设计资料