uibutton - iOS is it possible to change the image of a button and populate a label with text with the press of one button? -
i want able change image of button, no tick tick, , populate label text 1 press of button. possible @ all?
here code have far button cannot make work:
#import "viewcontroller.h" @interface viewcontroller () @end @implementation viewcontroller @synthesize loclabel; - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. } - (ibaction)pickimage:(id)sender { uiimage *btnimage1 = [uiimage imagenamed:@"submitbooking-pressed.jpg"]; [sender setimage:btnimage1 forstate:uicontrolstatenormal]; loclabel.text = @"red"; }
many thanks
update
it seems throwing me .h file , highlighting the
@property(nonatomic,retain) iboutlet uilabel *loclabel;
part of it.
this .h file. there have done wrong?
#import <uikit/uikit.h> @interface viewcontroller : uiviewcontroller { iboutlet uilabel *loclabel; } @property(nonatomic,retain) iboutlet uilabel *loclabel; - (ibaction)pickimage:(id)sender; @end
- (ibaction)pickimage:(uibutton *)sender { uiimage *btnimage1 = [uiimage imagenamed:@"submitbooking-pressed.jpg"]; uiimage *btnimage2 = [uiimage imagenamed:@"anyimage.png"]; uiimage *btnimage3 = [uiimage imagenamed:@"anyimage2.png"]; [sender setimage:btnimage1 forstate:uicontrolstatenormal]; [sender setimage:btnimage2 forstate:uicontrolstatehighlighted]; [sender setimage:btnimage3 forstate:uicontrolstateselected]; loclabel.text = @"red"; }
u can choose ever state required. or can use combined states adding uicontrolstatenormal|uicontrolstatehighlighted or uicontrolstateselected | uicontrolstatehighlighted
Comments
Post a Comment