zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    多级菜单 menu
    PHP 在线 编辑 解析
    [转]在PHP语言中使用JSON
    [转]SSIS ADO.NET vs OLEDB
    [转]SSIS高级转换任务—在Package中是用临时表是需要设置RetainSameConnection属性
    [转]SSIS高级转换任务—行计数
    [转]SSIS Recordset Destination
    [转]SSIS: By coding
    [转]SSIS cannot convert between unicode and non-unicode string
    [转]How to handle Failed Rows in a Data Flow
  • 原文地址:https://www.cnblogs.com/endtel/p/4847468.html
Copyright © 2011-2022 走看看