NSButton with an Image - macos

I have a question. I have a button on my .xib and a background image. I set an image to my button through the attributes inspector, but when I run the program and press the button, this happens:
If I don't press it, it looks fine. What's wrong?

This is controlled by the setHighlightsBy: property on the cell. It's probably set to NSChangeBackgroundCellMask by default. Try setting NSContentsCellMask (if you have an alternate 'pressed' image) or NSNoCellMask.

Related

Button not showing in .nib file

So I downloaded CircleView and tried to change the code. The program came with a button, color wheel, 2 sliders, and a view. When ever I add anything (Slider, button, textfield), on run time the things I added wouldn't show up. What am I not doing?
It's a .nib file.
This is the edit page.
This is what I see when running the program.
As you can see, the button and textfield doesn't appear during run time.
By default, when you add a button, the autoresizing mask (aka "springs and struts") are set to the following:
That means that when you resize the window, the button you added will stay in the same spot it originally was, instead of being "pulled" down with the edge of the window. This could potentially cause the buttons or textfields you added to be hidden behind the circle view once you resize the window large enough.
To prevent that from happening you'll want to change the autoresizing mask of the items to be "pinned" to the bottom edge of the window, so that they look like in the following image:
To do that, click on the red I bar at the top of the square to remove it, and then click on the lower I area to turn it on.
Note that you can also select multiple buttons or textfields at one time to change them all at the same time.

Text in disabled round textured NSButton is not greyed out

I have an NSButton created in Interface Builder with the style "Round Textured". When the button is disabled, the text colour does not go grey as you would expect. Oddly enough when the button contains an image instead of text, the image does go grey, as seen in the below screenshot (top buttons are enabled, bottom buttons are disabled).
How can I get the text to go grey when the button is disabled?
Update: So it gets weirder: the view containing the button is shown in a popover and every second time the view is shown the button is greyed out.
It seems, at least in Yosemite, as long as you set button.wantsLayer = YES on the button view, that it then works. Go figure.

Navigation Controller back button image manipulation

I am, no matter what I try, unable to change the back button colour and default image.
Here is what it looks like rite now:
The leftmost arrow is the default and the right most is my custom arrow.
This is how I set it up in storyboard:
How do I remove that pesky default image and replace it with my own?
The button you are adding is overriten by the default back button provided by the navBar. The only way you could do that is by adding it from within the code and by creating an UIButton inside the UIBarButton with an image and/or text, you should set its action a popViewController.

cocoa: how to make a image button like app store

Instead of push button, I want to implement a image button like app store, as you can see in the image bellow:
after I click Featured image button, the image turns blue.
My question is:
how to make a image button?
how turn the color after click it?
I can add a image into a square button, but it doesn't like the app store button.
Create another image - blue image and just change it using -setImage in button's action (example at the bottom). Use Gradient Button's style (It can be changed in Attributes Inspector -> Style) then You can change button's size easily. Don't forget to choose button's type to Momentary Change (it will remove white background when pushing button). Also remove border, unchecking Attributes Inspector -> Visual -> bordered checkbox. Add alternate Image (Your blue image).
Example: (when button is clicked it will be changed to blue image)
-(IBAction)buttonAction:(id)sender {
[buttonOutlet setImage:[NSImage imageNamed:#"yourBlueImageFromResources"]];
}
Note: don't forget to IBOutlet button to buttonOutlet.

How do I add a title to a button which has a custom image?

I made a button with IB then added custom images for different states but my title never appears on my button. How can I fix it? In fact, I just want to add my text over the image.
You can set your button images as background images in interface builder, then the text will appear.
It will not appear because the image is on top of it, you can either:
1) Use backgroundImage instead of image
2) Create an image with the text already on it
3) Create a button with a transparent part where the text will go
4) Have your image and your text in the button, but say one on the left and one on the right, you can do this with this properties: titleEdgeInsets and imageEdgeInsets
5) Add the label and uiimage as subviews of uilabel.
start with a regular button type in the title and switch it to a custom button, if you want the background to be changed import and use the command yourButton.backgroundColor = [UIColor grayColor];
Try to change the Button type to "Custom" and then add the image as Background Image. Now u will be able to see the desired look.

Resources