Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

printf

macrumors regular
Original poster
Aug 27, 2008
105
0
First off, i'm going to explain my approach, but if you're an expert at core text, go straight to the bottom where I explain exactly what I'm after.

Now, maybe I'm the only one who's struggling with this, because I'm not seeing much else about it in google land, but how can i easily layout text using top and left as the origin?

The following is usually what I see recommended, but there are issues that creep up almost immediately when going this route:
Code:
CGContextTranslateCTM(context, 0.0f, rect.size.height);
CGContextScaleCTM(context, 1.0f, -1.0f);

for example, the only way to position text down is by making the y value negative as shown here:
Code:
CGPathAddRect(path, NULL, CGRectMake(0,-50,100,rect.size.height));

that might be forgivable, but if i'm forced then to use the height of the view/context. if not, it pushes the text down toward the bottom:
Code:
CGPathAddRect(path, NULL, CGRectMake(0,-50,100,200));

I tried playing with the text matrix, but it had no effect on it:
Code:
CGContextSetTextMatrix(context, CGAffineTransformMakeTranslation(0, 200));




OK, so all i really want is to specify a rectangle and for core text to display the text at the exact pixel location regardless of any width/height combination. How can I accomplish this?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.