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.
Related
Hi Im new to Xcode7 and Swift2 and I am trying to change the color of the buttons I am adding to my storyboard. Is there a way to change the color of the button in Xcode7? All I see are options to change color of text and add background image to a button but no change button color.
A button has many parts / aspects, so what do you mean by the "button color"? You probably mean the button's background color. If you scroll down in the button's attributes inspector, you'll come to the background color. The reason it's so far down is that it's a View (UIView) property, not merely a button (UIButton) property.
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.
Can I just want to replace the appearance by setting a property of NSButton?
I am able to change the appearance by using the "image" property of the button but I got an ugly gray rectangle whenever the custom button is clicked (the image has a transparency). Is there a way to hide that rectangle?
Thanks.
The following call changes the behavior by making image be darkened when clicked:
[[button cell] setHighlightsBy:NSContentsCellMask];
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.
I could not find a way in the documentation to tell an NSButton to resize its image to fill up the whole button. Is there a way to do this programatically?
The closest you'll get is -setImageScaling: ... look up the constants to see how the image will be scaled within the button cell, given its bordered state and bezel type.
If you're looking to replace the standard button entirely with your image (ie, the button cell doesn't draw itself at all - your image serves as the entire visual representation), turn off the border (-setBordered:).
All of these options can be configured in IB as well. A tip: in IB, hover the mouse over any setting in the inspector panel - most if not all give you a hint that shows what method controls the behavior affected by the setting's control.