I originally posted this in the iphone programming section, but having thought about it, it probably makes more sense to post this here since core text isn't exlusive to the iphone, and more importantly, it probably isn't used as much by iphone developers as os x developers, so here goes:
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:
for example, the only way to position text down is by making the y value negative as shown here:
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:
I tried playing with the text matrix, but it had no effect on it:
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?
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?