Ios 在CGContext上翻转旋转的文本
图片: 我想得到90-270度的文本(文本“Aroma 7”到“Aroma 17”),旋转180度 我的代码:Ios 在CGContext上翻转旋转的文本,ios,objective-c,xcode,cgcontext,Ios,Objective C,Xcode,Cgcontext,图片: 我想得到90-270度的文本(文本“Aroma 7”到“Aroma 17”),旋转180度 我的代码: for (int i=0; i<24; i++) { CGContextSaveGState(context); CGContextRef context = UIGraphicsGetCurrentContext(); NSString *str = [NSString stringWithFormat:@"Aroma %d", i]; CG
for (int i=0; i<24; i++) {
CGContextSaveGState(context);
CGContextRef context = UIGraphicsGetCurrentContext();
NSString *str = [NSString stringWithFormat:@"Aroma %d", i];
CGContextTranslateCTM(context, radius, radius);
CGContextRotateCTM(context, i * 15 * M_PI/180.0);
[[UIColor whiteColor] set];
CGContextTranslateCTM(context, - (radius), -(radius));
CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0]
constrainedToSize:rect.size
lineBreakMode:(NSLineBreakByWordWrapping)];
[str drawAtPoint:CGPointMake(((radius * 2) - 10) - size.width, radius) withFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
CGContextRestoreGState(context);
}
for(int i=0;i这将产生所需的输出:
for (int i=0; i<24; i++) {
CGContextSaveGState(context);
CGContextRef context = UIGraphicsGetCurrentContext();
NSString *str = [NSString stringWithFormat:@"Aroma %d", i];
CGContextTranslateCTM(context, radius, radius);
CGContextRotateCTM(context, i * 15 * M_PI/180.0);
[[UIColor whiteColor] set];
CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0]
constrainedToSize:rect.size
lineBreakMode:(NSLineBreakByWordWrapping)];
CGContextTranslateCTM(context, radius-10-size.width/2, size.height/2); // (1)
if (i >= 7 && i <= 17)
CGContextRotateCTM(context, M_PI); // (2)
[str drawAtPoint:CGPointMake(-size.width/2, -size.height/2) withFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
CGContextRestoreGState(context);
}
for(inti=0;i=7&&i)这真是太棒了。如果可以的话,我会多次投票。