Bro*_*nix 5 iphone nsstring ipad ios4
我正在使用以下内容来渲染一些文本UIView.
- (void) drawRect:(CGRect)rect
{
NSString* text = @"asdf asdf asdf asdf asdf asdf asdf";
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
CGContextFillRect(context, rect);
CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip);
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextSetShouldSmoothFonts(context, YES);
UIFont* font = [UIFont fontWithName:@"ArialRoundedMTBold" size:20.0f];
CGSize textMaxSize = CGSizeMake(rect.size.width - 20.0f, rect.size.height);
CGSize textSize = [text sizeWithFont:font constrainedToSize:textMaxSize lineBreakMode:UILineBreakModeWordWrap];
CGRect textRect = CGRectMake(10.0f, 10.0f, textSize.width, textSize.height);
[text drawInRect:textRect withFont:font];
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap];
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
}
Run Code Online (Sandbox Code Playgroud)
没有[text drawInRect]人像我期望的那样包装文本.TextSize计算正确但绘制只是渲染一行.
更新:
解决了.
CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip);无论UILineBreak选择何种模式,设置都将导致文本剪辑.设置CGContextSetTextDrawingMode(context, kCGTextFillStroke);解决了这个问题.
解决了。
设置 CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip); 无论选择何种 UILineBreak 模式,都会导致文本被剪切。设置 CGContextSetTextDrawingMode(context, kCGTextFillStroke); 解决了这个问题。
| 归档时间: |
|
| 查看次数: |
5419 次 |
| 最近记录: |