• 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(0, [self.text length])];
       
      CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString);
       
      CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [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, 0, path.bounds.origin.y);
        CGContextScaleCTM(context, 1, -1);
        CGContextTranslateCTM(context, 0, -(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

  • 相关阅读:
    HIVE的基本操作
    sqoop数据迁移
    工作流调度器azkaban
    C/s模式与B/S模式
    自动装箱和拆箱所带来的问题(1)“==”问题
    线程死锁
    模拟售票
    线程之间的通信
    线程同步引发的安全问题
    sql server 与 mysql在自定以数据类型的区别
  • 原文地址:https://www.cnblogs.com/endtel/p/4847468.html
Copyright © 2020-2023  润新知