Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

azrael2000

macrumors newbie
Original poster
Nov 13, 2007
6
0
Hi there.

I am running Snow Leopard and running Xcode 4.0.

I am trying to change the color of text in a label, however I can't seem to get it to work.

I read the developer documentation, and when I use the line:
Code:
[myText setTextColor:<#(NSColor *)#>

I can't find the proper syntax.

Can someone tell me what I am supposed to do? I know that NSColor is looking for a pointer, but nothing I try seems to work.

Simple for others, perhaps, but I am just starting here.

UPDATE: I am getting closer. This doesn't work, but seems to be on track, if that seems right
Code:
 [myText setTextColor:(NSColor *) redColor];

The program builds ok, but when I run it and click the button to which this is attached, I crash...

Regards
 
Last edited:

ytk

macrumors 6502
Jul 8, 2010
252
5
You're very close! The key is that redColor is a class method of NSColor (that returns an object of type NSColor *), so you need to call it like this: [NSColor redColor]

See if you can figure out the correct statement now. :)
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
Since you're just starting, what tutorial or book are you learning from? Be specific. Exact URL, or title, author, and edition number.


Syntax is fundamental. If you don't know the correct syntax, you need to learn it. After you learn it, you should be able to answer the NSColor question yourself. Conversely, if you don't know correct syntax, then having the answer for NSColor won't help you in any other situation.

So the best solution is to go back to the fundamentals, learn the correct syntax, then apply that to the NSColor situation.
 

azrael2000

macrumors newbie
Original poster
Nov 13, 2007
6
0
Hi there.

I haven't found any good books or tutorials. I have been teaching myself, though I do have some grounding in building console applications.

I have been going through the documentation that goes through Xcode, and did my best reading it with what limited knowledge I have. If I had a better idea of what I was looking for IN the documentation, that would help! <smile>

Regards
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
I haven't found any good books or tutorials. I have been teaching myself, though I do have some grounding in building console applications.

What other programming languages do you already know? What language were the console applications written in?

If already know C, or something similar to it, try Learning Objective-C :A Primer.

Also see the link here:
https://developer.apple.com/library...Conceptual/DevPedia-CocoaCore/ObjectiveC.html

Find more with this google search terms:
objective-c site:developer.apple.com

There's also a Getting Started section on the main Apple Developer navigation page.
http://developer.apple.com/library/mac/navigation/


Xcode's documentation is reference documentation, not a tutorial.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.