【问题标题】:rendering a new line in a string (\n) with drawRect使用 drawRect 在字符串 (\n) 中呈现新行
【发布时间】:2012-09-02 09:35:29
【问题描述】:

我正在尝试使用 drawRect 呈现带有新行(换行符 \n)的字符串。

下面的代码将 my 字符串呈现为单行,没有换行符,即使我使用的是 \n 字符。请参阅倒数第二行。

UIFont *font =  [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:fontSize];
CGPoint point = CGPointMake(0,0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 4.0);
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
CGContextSaveGState(context);
[@"test \n test" drawAtPoint:point withFont:font];

CGContextRestoreGState(context);

【问题讨论】:

    标签: ios xcode newline line-breaks


    【解决方案1】:

    使用

    - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode
    

    绘制字符串的方法。

    【讨论】:

      猜你喜欢
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多