PDA

View Full Version : How to go about images on top of buttons?




dantastic
Jan 28, 2011, 03:43 PM
Hi again,

I'm trying to understand how to go about doing this.

I have an app, on launch it draws a button 300x300 with and image of a big button.

If you press the big button it fades out and get replaced by another button (just a different colour)

So far so good, I have been able to create buttons with images on there that animate the switch nicely.

So far I have only been using IB to add these buttons to one single view, bit of a side question but how can I guarantee the order of the images (I.E. Button 1 is always the visible one at start).

Right, back to my actual question. On top of this second button I want another image, much smaller with transparent background, that will move around on top of the button.
- will my button still be clickable?
- how would I go about doing this? Can I just stack images on top of eachother or do I need to stack views etc?

I have been trying to google a tutorial that will explain these bits so if you'd happen to know one... :D

thanks!



MaxFreud
Jan 28, 2011, 08:42 PM
Ok... I'm not too experienced yet, but here's a shot:

UIButton is a UIView, which has a hidden property. You can check this in IB for your 2nd button, and then set it for button 1 and turn off for button 2 when you want to switch between them. This guarantees that button 2 is invisible at start.

About the floating image, I actually don't know how you would do this. My hack would be to have a floating imageview but not on the button itself but just somewhere on the window. It would normally be invisible. When you swap your button, you also set this floating imageview to visible. Since your big button is not gonna be moving, you'll know its coordinates, so you can constrain the coordinates of the imageview to stay within the bounds of the big button.

Hope that made sense or was mildly helpful.