Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: set image on button only for default state, not also selected

I am new to Xcode and iPhone programming in general.. I have a simple problem thats bugging me.. I want to set an image on a button, for it's default state. So I select the button, and in the "Show the attributes inspector"-tab, I select "state config" to be default, then I find the desired image in "image"-drop down list...

Problem:

I change the "state config" to selected, and the image is still on. I need the image to only be on in default state. I have same problem if i want different font size of the title text in default- and selected-state. I'm using Xcode 4.6 and writing for iOS 6.1.

like image 379
Wiingaard Avatar asked Feb 17 '23 18:02

Wiingaard


1 Answers

There are two ways.

First way, programmatically:

[button setBackgroundImage:buttonimg forState:UIControlStateSelected];
[button setBackgroundImage:buttonimg forState:UIControlStateNormal];
[button setBackgroundImage:buttonimg forState:UIControlStateHighlighted];

Second way, using IB Builder:

Like the img:

enter image description here

You have a option of selecting a state config. Based on the config, you can set the image under the section called "Image".

Hope this helps...

like image 52
lakshmen Avatar answered Apr 29 '23 17:04

lakshmen