大佬教程收集整理的这篇文章主要介绍了如何在iPad中使用CTRunDelegate?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
任何有关这方面的指示都将受到高度赞赏.
提前完成.
更新
这是绘制简单文本的视图的示例代码(请注意,此处没有内存管理代码).
@implementation View /* Callbacks */ void MyDeallocationCallback( void* refCon ){ } CGFloat MyGetAscentCallback( void *refCon ){ return 10.0; } CGFloat MyGetDescentCallback( void *refCon ){ return 4.0; } CGFloat MyGetWidthCallback( void* refCon ){ return 125; } - (void)drawRect:(CGRect)rect { // create an attributed string NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:@"This is my delegate space"]; // create the delegate CTRunDelegateCallbacks callbacks; callbacks.version = kCTRunDelegateVersion1; callbacks.dealloc = MyDeallocationCallback; callbacks.getAscent = MyGetAscentCallback; callbacks.getDescent = MyGetDescentCallback; callbacks.getWidth = MyGetWidthCallback; CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks,NULL); // set the delegate as an attribute CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attrString,CFRangeMake(19,1),kCTRunDelegateAttributeName,delegate); // create a frame and draw the text CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString); CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path,NULL,rect); CTFrameRef frame = CTFramesetterCreateFrame(frameSetter,CFRangeMake(0,attrString.length),path,NULL); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetTextMatrix(context,CGAffineTransformIdentity); CGContextSetTextPosition(context,0.0,0.0); CTFrameDraw(frame,context); } @end
文本中“委托”和“空格”之间的空格字符大小由运行委托控制.
以上是大佬教程为你收集整理的如何在iPad中使用CTRunDelegate?全部内容,希望文章能够帮你解决如何在iPad中使用CTRunDelegate?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。