NOrder
NOrder

Reputation: 2493

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:

enter image description here

after I click Featured image button, the image turns blue. My question is:

  1. how to make a image button?
  2. 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. enter image description here

Upvotes: 1

Views: 1488

Answers (1)

Justin Boo
Justin Boo

Reputation: 10198

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.

Upvotes: 3

Related Questions