I have need of rendering text manually to a UIView, along with graphics. I realise that I could probably use a UITextView as a subview and position it, but for now I'd like to learn the right way to render it manually.

My aim is to render a particular string in a particular colour, in a particular font (or, any Sans Serif of the system's choosing would be enough here) and a particular font size.

First, a quick question about +stringWithFormat: If I want to have a literal string as one of the parameters to the format, which is correct / best:

NSString *textToDraw = [NSString stringWithFormat: @"%s",
        "my string"];

or

NSString *textToDraw = [NSString stringWithFormat: @"%@",
        @"my string"];

(or something else?).


Now, I'm led to believe that you can either use CGContextXXX calls, or Cocoa text drawing. I seemed to fall flat on my face with the Cocoa way, so I was trying to use this:
                                                            
CGContextShowTextAtPoint(contextRef, 0, 40,
        [textToDraw UTF8String], [textToDraw length]);

(since -cString: is deprecated). But I end up with garbage characters and I don't know if I'm using +stringWithFormat: incorrectly, or CGContextShowTextAtPoint().

What is the 'correct' or best recommended way to render text, lines and filled primitives? For the Cocoa way of rendering text, how do I control font face / size? The sample I found used NSDictionary for the attributes but it won't compile the NSFontAttributeName the (web) sample used for the key.

Thanks in advance.

--
Jason Teagle
_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to