The question title is kind of vague, but I really don't know what the thing is called.
I am trying to create one of those yellow informational popup things. Anyone can tell me what they're called and how I can create them?
That's called a tool tip. You can set the tool tip for any NSView using setToolTip:.
If you are using NSTextView, you can even set an attribute for a certain range in NSTextstorage, that displays the Tooltip.
Something like:
[textStorage addAttribute:NSToolTipAttributeName
value:error.description
range:range];
Related
I've worked with VB.NET in the past.
VB.NET is an object oriented language, but since all view objects have a name, you can double-click on (ButtonX) and it will take you to where you write your code for the (ButtonX-clicked) event .. if you want to set the background color of (LabelX) you just write
(LabelX.backgroundcolor = red).
I am now trying to learn how to write programs for OS X.
I've gotten to the point where I can click a button and display "hello" in a label, but I don't know where to go from there.
How do I get a button click event to also change the background color of a label box to red?
Can you provide sample code?
I do not have a good understanding of classes.
You may want to do some reading on Cocoa event handling. It could provide some basic knowledge on how to deal with object events in OS X.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html
In this case the code you need is not that different in structure from what you know from VB.NET.
You say you already have the code to put "Hello" into the label, so you must have a reference to the label stored in a variable of type NSTextField *, let's say you've called this myLabel. Lookup NSTextField and you will see it has two methods backgroundColor and setBackgroundColor: - and any pair of methods following this naming pattern can be referenced as a property. So to set the background color of your label all you need is:
myLabel.backgroundColor = [NSColor redColor];
which should not look too unusual to a VB.NET person.
If you don't wish to use the property syntax you can instead write:
[myLabel setBackgroundColor:[NSColor red]];
and you will see this a lot in code as the property syntax is fairly new in Objective-C. HTH.
I have an NSTextView and want to be able to tell when the user highlights (selects) a portion of the text, so that I can make changes to it. The NSTextViewDelegate protocol doesn't seem to have a method for this. Is there a way to capture this event?
Are you sure - (void)textViewDidChangeSelection:(NSNotification *)aNotification doesn't do the trick? It's part of NSTextViewDelegate (reference). If it doesn't work the way you want, what specifically are you looking for?
I need to display a message similar the following attachmnet
I dont know the technical term what exactly it called in cocoa terminology.
So,I could not google it also.just I am interested to know how can I implement this feature.
They're called tooltips and can be added to any view. You can add them programmatically like so:
[searchField setToolTip:#"Hello World!"];
I use NSButton with empty title and image on it, and it cannot be accessed with VoiceOver.
But when I'm setting title (VoiceOver seems to use title), NSButton tries to show it.
I think there should be an easy way to not display title, or to set button text, used by VoiceOver, however quick search didn't give any results yet.
P.S. I'm creating button programmatically.
you must assign the accessibilityLabel to the image object directly, It works this way.
Solved issue - added subclass for NSButtonCell, which does nothing in drawTitle: method and returns NSZeroRect. Seems to work ok.
I am trying to customize an IKImageBrowserCell to have something close to the Finder.
For the moment my issue is to have a title in 2 lines. Do you have any experience of what need to be modified in order to achieve this?
Thanks and regards,
Yes, this is possible by drawing your title on a CALayer returned from the - (CALayer *)layerForType:(NSString *)type method of a subclassed IKImageBrowserCell.
See my answer here.