Separate names with a comma.
Discussion in 'Mac Programming' started by xcoder78, Jul 9, 2007.
How do you make pictures clickable in Xcode? Im using them in a browser im making.
Do you really mean: "How do I assign my own custom icon to a NSButton"?
Hey, I am curious as to how this will be done as well. I will need images and textfields to be clickable. If the only way to do this is with an NSButton, than how would I make the button part invisible so all I can see is the text (I need text with a transparent background). As well of course for the image.
Just looking at the documentation. A NSTextField and NSImageView inherits from NSControl which has the method
This sounds like exactly what I want.
So... I could be completely wrong but I think you'll have to subclass, in your case an NSImageView and override the performClick method. In there you do whatever you gotta do.
-performClick: makes it look like the view was clicked with a mouse, but it doesn't handle an actual click event. I think what you want is to subclass and override -mouseDown:
The trick is that you make a button and apply the image to the button. Then take the border off of the button( A check box in the attributes panel)
Ok, I subclassedd NSImageView but how do i override the perform click method?
Did you read the above? You don't want to override performClick: you want to override mouseDown: or maybe mouseUp: or perhaps both.
Simply add the appropriate method to the class (just a method with the same signature as that in the documentation for NSControl) and go from there.
How do you apply the image again?
Not sure what you mean? Do you mean how do you set the image the view is displaying?
The it's all in the documentation
Yeah i'm pretty sure that is what he means.
I will be trying this mousedown mouseup stuff very shortly xcoder78. I'll show you my implementation then.
Be sure to check out that link robbieduncan posted. Explains the methods in detail.
Thats how you do it
You select a picture on your mac, drag it into your xcode project, add a Round Rec Button, in the Attribute Inspector you change Type: from round rec to custom. In image you select the picture you added previously.
On the off chance that I understand what you're trying to do, you should set up your button in Interface Builder, set that button's picture (not background) to one of the picture assets (which you have already moved into Xcode). Then hook that button up to Xcode normally (if you have Xcode 4 this you can control drag from the button to the .h file and the IBAction and method in both the .h and .m will be set up automatically, you just put your code in the new method).
If the picture never changes, you're done. No programming. If the picture changes, then set button.image (I think) to the new picture when necessary.