Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Fritz Anderson
On 24 May 2012, at 1:57 PM, Jason Teagle wrote: > If the CGContextXXX methods shouldn't be used, then they shouldn't be in the > API - or should be marked as deprecated. There's nothing in the docs (with > Xcode 3.X, at least - maybe it's changed since) to indicate that these were > the worst w

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Jason Teagle
Thanks for all the replies regarding %s vs. %@, and the rather disastrous attempt at using CGContextXXX methods. Even if I had fixed all the other issues, I was using CGContextSelectFont incorrectly anyway. I didn't have a hope. That, unfortunately, is down to documentation not being complete /

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Ken Thomases
On May 24, 2012, at 2:49 AM, Jason Teagle wrote: > 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 >

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Jens Alfke
On May 24, 2012, at 5:50 AM, Jason Teagle wrote: > (I've since discovered that the %@ and @"xxx" way works just fine, so I'll > stick with that. Good :) The problem with using "%s" is that it doesn't work well with non-ASCII characters. Cocoa has to assume some character encoding to map the by

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Kyle Sluder
On May 24, 2012, at 10:36 AM, Manfred Schwind wrote: >> CGContextShowTextAtPoint(contextRef, 0, 40, >>[textToDraw UTF8String], [textToDraw length]); > > One bug I see here: you're passing a wrong length parameter. Another bug: CGContextShowztextAtPoint takes characters encoded in MacRoman,

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread glenn andreas
On May 24, 2012, at 9:36 AM, Manfred Schwind wrote: >> CGContextShowTextAtPoint(contextRef, 0, 40, >> [textToDraw UTF8String], [textToDraw length]); > > One bug I see here: you're passing a wrong length parameter. > CGContextShowTextAtPoint expects the length of the char array (number of >

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread James Montgomerie
On 24 May 2012, at 15:36, Manfred Schwind wrote: >> CGContextShowTextAtPoint(contextRef, 0, 40, >> [textToDraw UTF8String], [textToDraw length]); > > One bug I see here: you're passing a wrong length parameter. > CGContextShowTextAtPoint expects the length of the char array (number of > byte

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Manfred Schwind
> CGContextShowTextAtPoint(contextRef, 0, 40, > [textToDraw UTF8String], [textToDraw length]); One bug I see here: you're passing a wrong length parameter. CGContextShowTextAtPoint expects the length of the char array (number of bytes of the UTF-8 encoded string), but you'e passing the numb

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Jason Teagle
You probably want UILabel. UITextView is a much more heavyweight class that supports editing as well as display. (My bad, a label is called a TextView on Android - got mixed up.) These both are just wasting CPU cycles and adding extraneous code. Simply use: NSString *textToDraw = @"my stri

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Jason Teagle
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 ad

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Conrad Shultz
Greetings Jason, On 5/24/12 12:49 AM, Jason Teagle 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. Please see t

Re: stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Mikkel Islay
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 ad

stringWithFormat / Rendering Text (iOS)

2012-05-24 Thread Jason Teagle
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 parti