0

The project I'm working on in Xcode is done in landscape. I may be doing something wrong, but I've had to rotate every image 270 degrees before adding them to my file.

NSString *strFromInt = [NSString stringWithFormat:@"%d",score];
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(gc, 1, 1, 1, 1);
NSString *str = (@"Score ");
UIFont *uif = [UIFont systemFontOfSize:40];

[strFromInt drawAtPoint:CGPointMake(150, 10) withAttributes:@{NSFontAttributeName:uif}];
[str drawAtPoint:CGPointMake(10, 10) withAttributes:@{NSFontAttributeName:uif}];

When I try including a score (in the above code), the text runs along the wall vertically. Any way to fix this (preferably in a method that doesn't make me have to rotate all 47 of my images again)?

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
  • This has nothing to do with the Xcode IDE and everything to do with iOS. I see you're drawing the string, but if it were some other kind of object (e.g. UILabel), there might be an easier way to do this. – Michael Dautermann Dec 23 '13 at 13:34

2 Answers2

0

I suspect the issue is that you are using CoreGrphics to place everything on the screen. Using UILabel's etc. would do this for you as these are self contained views with logic behind them as apposed to to instruction the OS to draw the letters for you.

Is there a reason you can't use UIlabel ?

Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56
  • I tried adding a UIlabel, but kept running into issues most likely because pretty much all of my code is in the main view. When I tried adding the code to the view controller, it said that "self" was not identified – Justin Buergi Dec 23 '13 at 17:01
  • @JustinBuergi ? That doesn't really make sense. Using UILabel's is far simpler than CoreGraphics. If you had issues with too much code in the main view, then it sounds like you need to pass off work to objects. Why not create a UILabel category to return an instance of a label with all your custom settings fill in, well the ones that won't change, most likely font, size, colour, alignment etc. This is a level of simplicity you won't get with CoreGraphics. I can assure you if your going down this road with CoreGraphics, you need to do EVERYTHING yourself – Simon McLoughlin Dec 23 '13 at 17:05
  • @JustinBuergi I would re implement the UILabels and then post an additional question with whatever those issues where, your trying to over complicate things for your self – Simon McLoughlin Dec 23 '13 at 17:06
-1

You can use UILable with clearColor. This will resolve your problem.

rene
  • 41,474
  • 78
  • 114
  • 152
Vaz
  • 79
  • 6
  • ??? where does the user suggest the issue is he didn't know how to set the UILabels background color. In no way does this answer his question – Simon McLoughlin Dec 23 '13 at 19:29