 |
 |
Drawing strings
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
What is the simplest way to draw strings into an NSView (or just draw strings anywhere)? I want to display numbers below some axes that my app draws using an NSBezierPath. I would just use NSTextView in IB, but I need to draw different numbers depending on some calculations.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
[myNSString drawAtPoint:NSMakePoint(x, y)
withAttributes:dictionary];
You can use an empty dictionary to test it.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
In case you want to see it, the drawAtPoint function is discussed in the NSStringAdditions file in AppKit.
-Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status:
Offline
|
|
Couldn't that be simplified even more? I seem to recall writing a Tic Tac Toe game that used only strings drawn to a NSView (like you are asking about). I think that you can nil the "withAttributes" parameter:
[myNSString drawAtPoint:NSMakePoint(x,y) withAttributes:nil];
Since I used this, I never even knew that a dictionary was supposed to be used for that parameter. Thanks Parallax, that is good to know!
Jeff.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Yup, there's a bunch of useful properties which you may like to know:
NSFontAttributeName (NSFont) - font and size
NSKernAttributeName (NSNumber) - Kerning (negative numbers make the text condensed)
NSForegroundColorAttributeName (NSColor) - font color
Listed at:
http://devworld.apple.com/techpubs/m...singAttrs.html
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Nov 2000
Status:
Offline
|
|
NSString drawAtPoint dosen't seem to allow you to draw at a negitive point. It goes back to 0,0. Is this true? Is there a way to draw at a negitive point?
------------------
Timothy Hatcher
Programmer/Designer @ MainNet Incorporated
__________________________________________
http://www.main-net.com
|
|
Timothy Hatcher / xenon
.:[ massinova.com ]:.
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
What about in Java? Does anyone know who to draw strings in Java? It seems like the examples above are for Obj-C.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|