• 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
Re: stringWithFormat / Rendering Text (iOS)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringWithFormat / Rendering Text (iOS)


  • Subject: Re: stringWithFormat / Rendering Text (iOS)
  • From: Mikkel Islay <email@hidden>
  • Date: Thu, 24 May 2012 10:43:58 +0200

Jason,

Have a look at this doc-page:
https://developer.apple.com/library/mac/ipad/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_text/dq_text.html
It discusses your options when drawing text with Quartz2D, and also mentions other techniques. One option of note is the NSString additions for UIKit for drawing text, which does most of what you want "out of the box".

Mikkel

Sent from my iPad

On 24 May 2012, at 09:49, Jason Teagle <email@hidden> wrote:

> 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

_______________________________________________

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: Jason Teagle <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>)
 >stringWithFormat / Rendering Text (iOS) (From: Jason Teagle <email@hidden>)

  • Prev by Date: Arc and autorelease
  • Next by Date: Multiple Inheritance
  • Previous by thread: stringWithFormat / Rendering Text (iOS)
  • Next by thread: Re: stringWithFormat / Rendering Text (iOS)
  • Index(es):
    • Date
    • Thread