Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-13-2009, 06:41 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 138
JohnMabassa is an unknown quantity at this point
Default Help needed in using png for buttons & handling the title

Hi,
I have made a couple of buttons using photoshop. Since I am gonna use that for my entire app, i didn't add the text. Now I added the image to my view using IB Button->Custom->image............ now I did like this

in viewController.h
Code:
{
  IBOutlet UIButton *myButton;
}

@property ...............................UIButton *myButton;
-(IBAction)buttonPressed;
@end
but i dont know how to handle it in the below function, (basically I have two images one for normal state and other one when button is pressed)

in viewController.m

Code:
-(IBAction)buttonPressed{

//I have a code here to load the next view

}
I have connected the button to myButton and buttonPressed, now when i click the image the loading of next view is happening but no indication is there to show that button was pressed ( basically i dont know how to use the second image when click i)

I have tried to add title on the image but IB is not allowing me to do that,the title comes out of the image once we finish typing.(other wise I will have to create same buttons with different titles using photoshop)
JohnMabassa is offline   Reply With Quote
Old 02-14-2009, 09:10 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 138
JohnMabassa is an unknown quantity at this point
Default

I figured out a way to do this ....... anyway I have to create all the buttons with the corresponding text using photoshop....these are the steps that i followed

1. Add the images to resource folder.
2. Open your view in IB and drag a button select Custon button.
3. Choose the required image from the image dropdown.
4. Create an IBOutlet in ur viewController.h

Code:
   {
      IBOutlet UIButton *myButton;
}
@property (nonatomic,retain) UIButton *mybutton;
-(IBAction)buttonPressed:(id)sender;
@end
5. In viewController.m

Code:
@synthesize mybutton;//under the implementation of interface
........
......
......
-(IBAction)buttonPressed:(id)sender{

[myButton setImage:[UIImage imageNamed:@"image.png"] forstate:UIControlStateHighlighted]; //(image.png)= the image which required to be shown when button needs to be pressed.

}
6. Go back to IB and connect the button to myButton and buttonPressed function( select touch down)

7. Build it and run you will be able to see your button changing to second image when u press it.


PS: I dont know whether this is the right way to do it, but it works. I am typing this in windows PC @ home..... no access to codes...so forgive me for typo errors
JohnMabassa is offline   Reply With Quote
Old 02-14-2009, 10:33 AM   #3 (permalink)
Don
Registered Member
 
Join Date: Jan 2009
Posts: 68
Don is on a distinguished road
Default

There are a couple ways to do this...

In IB, you can assign the images for the "Normal" / "Highlighted" (pressed) / "Selected" / "Disabled" states using the Attributes Inspector. Then you don't need to do any image assignments in code.

Depending on how your buttons look - since you started out saying 'one button style, different labels' - you could instead assign the "normal" and "pressed" images as the Background of each of the buttons, and then set individual Titles.

There are certainly times when coding has benefits over IB design, but for a "standard" task such as this, and since you are using IB anyway, I guess I'd say whichever way you're most comfortable with.

- Don
Don is offline   Reply With Quote
Old 02-14-2009, 12:17 PM   #4 (permalink)
Registered Member
 
Forsworn's Avatar
 
Join Date: Oct 2008
Location: Germany
Posts: 504
Forsworn is on a distinguished road
Default

Your buttonPressed: action will get fired each time the user presses this button.
It's not good to assing the image there.
Do this either in IB or the viewDidLoad method.
Forsworn is offline   Reply With Quote
Old 02-15-2009, 09:31 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 138
JohnMabassa is an unknown quantity at this point
Default

Quote:
Originally Posted by Forsworn View Post
Your buttonPressed: action will get fired each time the user presses this button.
It's not good to assing the image there.
Do this either in IB or the viewDidLoad method.
Actually I am doing a kind of trick here, in IB I have put lets say image1.png....say blue in color...... and when I press button , I am asking it to change the image to image2.png (white in color) so it will look like an animation.............I hope now u got what I am trying to do?
JohnMabassa is offline   Reply With Quote
Old 02-15-2009, 09:33 AM   #6 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: India
Posts: 138
JohnMabassa is an unknown quantity at this point
Default

Quote:
Originally Posted by Don View Post
There are a couple ways to do this...

In IB, you can assign the images for the "Normal" / "Highlighted" (pressed) / "Selected" / "Disabled" states using the Attributes Inspector. Then you don't need to do any image assignments in code.

Depending on how your buttons look - since you started out saying 'one button style, different labels' - you could instead assign the "normal" and "pressed" images as the Background of each of the buttons, and then set individual Titles.

There are certainly times when coding has benefits over IB design, but for a "standard" task such as this, and since you are using IB anyway, I guess I'd say whichever way you're most comfortable with.

- Don
Are you saying that it is possible to set the states in IB itself??.... OH Cool I haven't seen that lemme try that... thanks for the help
JohnMabassa is offline   Reply With Quote
Reply

Bookmarks

Tags
button image, custom button, png, title

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 327
5 members and 322 guests
Anwerbl, guusleijsten, HowEver, LEARN2MAKE, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,879
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:38 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0