Hello all,
For various reasons I'd like to implement a method similar in function
to NSString's -sizeWithFont: (UIKit addition). The difference is it
takes a CGFontRef. Here's a rough idea of the code (a slight
adaptation of Timothy Ritchey's TTFontCell code, and I apologize
because I can't find a link to it right now):
- (CGSize)sizeWithFont:(CGFontRef)font ofSize:(CGFloat)size
withKerning:(CGFloat)kerning {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFont(context, font);
CGContextSetFontSize(context, fontSize);
CGContextSetCharacterSpacing(context, kerning);
....
}
The code works — however, it can only be called within a UIView's
drawRect: method, for a valid context to be returned in
UIGraphicsGetCurrentContext();
This method is only useful really if it can be called *before* the
drawing code, for laying out views and such. I know that I need to
create a CGContextRef and push it on the UIGraphics stack. My question
is, what might be the best way to do this? I see I can use
CGPDFContextCreate or CGBitmapContextCreate... which makes sense here?
All I need to do is determine the size of a string w/ specified font,
not actually draw it.
Thanks,
Michael Hoy
michael.john....@gmail.com
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com