如何使用Core Graphics正确对齐文本

Ed *_*hin 2 text core-graphics ios

我想在使用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);
Run Code Online (Sandbox Code Playgroud)

hol*_*lex 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];
Run Code Online (Sandbox Code Playgroud)

更新

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