2

I'm trying to draw some text on the iPhone, but in landscape mode, where the home button is on the left. So I need to somehow twist the numbers (I'm guessing I use a transform) ?

Here's what I have now:

    CGContextSetRGBFillColor(context, 1.0, 0, 0, 1.0);
    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
    CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
    CGContextSetTextMatrix(context, CGAffineTransformMakeRotation(M_PI/2));
    CGContextSetTextDrawingMode(context, kCGTextFill);
    NSString *t = [NSString stringWithFormat:@"%i",seconds];
    const char *str=[t UTF8String];
    CGContextShowTextAtPoint(context,6.0,15.0,str,strlen(str));

What do I need to add to rotate the text so that it can be read when the phone is landscape with the home button on the left.

Ian
  • 3,619
  • 1
  • 21
  • 32
StanLe
  • 5,037
  • 9
  • 38
  • 41
  • i recommend that you implement shouldAutorotateToInterfaceOrientation: in your view controller so that the view rotates automatically, and set your autoresizing masks appropriatly – Felix Jul 02 '11 at 18:20
  • then you should only add UIInterfaceOrientationLandscapeLeft to UISupportedInterfaceOrientations in the info.plist file – Felix Jul 02 '11 at 19:31

1 Answers1

0

You have to apply two transformation matrices. The first one will flip the text and the second one will rotate it. Try the following code:

CGContextSetRGBFillColor(context, 1.0, 0, 0, 1.0);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
CGAffineTransform xform = CGAffineTransformMake(
                                                1.0,  0.0,
                                                0.0, -1.0,
                                                0.0,  0.0);
CGContextSetTextMatrix(context, xform);
CGContextConcatCTM(context, CGAffineTransformMakeRotation(M_PI_2));
CGContextSetTextDrawingMode(context, kCGTextFill);
NSString *t = [NSString stringWithFormat:@"%i",seconds];
const char *str=[t UTF8String];
CGContextShowTextAtPoint(context,6.0,15.0,str,strlen(str));
Radu Lucaciu
  • 706
  • 3
  • 6