简体   繁体   中英

Buttons in Iphone

Is it possible to manually assign an image to a button in the iphone sdk. What i wish to do is to assign a plain card background to a button. When a user clicks the button a picker appears the user makes a selection with the picker the buttons image will to the card selected? I have all the cards saved in my resources already.

Try the fiollowing code:

btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:[UIImage imageNamed:@"any.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"any_on.png"] forState:UIControlStateHighlighted];

You can use image in image view then over this image use an custom button and on click this button an IBAction will call suppose -(IBAction)call { myPicker.hidden=NO; } and in viewWillAppear myPicker.hidden=YES;

And use picker view delegate methods for your logic for picker view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM