• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
stringWithFormat / Rendering Text (iOS)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stringWithFormat / Rendering Text (iOS)


  • Subject: stringWithFormat / Rendering Text (iOS)
  • From: Jason Teagle <email@hidden>
  • Date: Thu, 24 May 2012 08:49:06 +0100
  • Organization: Organised Bytes Software

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: stringWithFormat / Rendering Text (iOS)
      • From: Ken Thomases <email@hidden>
    • Re: stringWithFormat / Rendering Text (iOS)
      • From: Manfred Schwind <email@hidden>
    • Re: stringWithFormat / Rendering Text (iOS)
      • From: Conrad Shultz <email@hidden>
    • Re: stringWithFormat / Rendering Text (iOS)
      • From: Mikkel Islay <email@hidden>
References: 
 >applicationDidHide - Not Getting Triggered? (From: Jason Teagle <email@hidden>)
 >Re: applicationDidHide - Not Getting Triggered? (From: Ken Thomases <email@hidden>)
 >Re: applicationDidHide - Not Getting Triggered? (From: Jason Teagle <email@hidden>)
 >Re: applicationDidHide - Not Getting Triggered? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: NSMutableData capacity
  • Next by Date: Arc and autorelease
  • Previous by thread: Re: applicationDidHide - Not Getting Triggered?
  • Next by thread: Re: stringWithFormat / Rendering Text (iOS)
  • Index(es):
    • Date
    • Thread