2

在使用 Core Graphics 绘图时,我想右对齐几个文本。下面是我现在用来绘制文本的代码。如何绘制几个右对齐的文本?

CGContextSelectFont(context, "Helvetica-Light", 10.0f,kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetFillColorWithColor(context, _privateColor.CGColor);
CGContextShowTextAtPoint(context, point.x, point.y, [text cStringUsingEncoding:NSUTF8StringEncoding], text.length);
4

2 回答 2

5

也许你正在寻找这样的东西......

[@"Any text what you like to show" drawInRect:CGRectMake(0.f, 0.f, 320.f, 80.f) withFont:[UIFont fontWithName:@"Helvetica-Light" size:10.f] lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentRight];

更新

不幸的是,这种方式在 iOS7+ 中已被弃用。来源

于 2013-02-17T20:40:55.380 回答
0
[@"your Text" drawInRect:CGRectMake(0.f, 0.f, 320.f, 80.f) withAttributes:"dictionary with text attributes"];

这里的属性是指文本字体、文本大小、对齐方式等。

可以使用带有文本 ielineBreakMode 等的 NSMutableParagraphStyle 对象设置对齐方式

于 2017-02-28T07:13:30.487 回答