Re: stringWithFormat / Rendering Text (iOS)
Re: stringWithFormat / Rendering Text (iOS)
- Subject: Re: stringWithFormat / Rendering Text (iOS)
- From: Jason Teagle <email@hidden>
- Date: Thu, 24 May 2012 13:50:18 +0100
- Organization: Organised Bytes Software
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 string";
OK, I guess I didn't expect anyone to take me literally there. I
obviously wouldn't use that technique for a single string - I did say
'one of the parameters'. I only cut out other parameters for clarity.
(I've since discovered that the %@ and @"xxx" way works just fine, so
I'll stick with that. My doubts came from CGContextXXX not working
properly.)
Whoa, let's back up here. There is no way that using Quartz/Core
Graphics is *easier* than using the Cocoa text drawing functionality
(particularly the NSString UIKit additions). If you "fall flat" using
the latter, you shouldn't even consider making life yet harder for yourself.
It wasn't that it was easier - it was that the CGContextXXX sample I had
(from the Apple docs) compiled but didn't quite work (so almost a
success), but the Cocoa sample I found (not from their docs - if it's in
them somewhere I haven't found it yet) didn't even compile.
What did you try in Cocoa and what were the results?
...
NSFontAttributeName is declared in the NSAttributedString *AppKit*
additions, which isn't available on iOS. Core Text on iOS has
That was what was wrong - couldn't compile it.
I've since found a working Cocoa sample - the problem of not being able
to use the font I wanted was that I hadn't yet found
-drawAtPoint:withFont:. I've got it working now.
(And no, I haven't forgotten that using UILabel is preferable.)
--
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