iphone - change image of UIBarButton -
my target change image of uibarbutton (which use iboutlet) programmatically.
i found solution on stackoverflow change-image-of-uibutton-with-other-image. not working on ios 4.2.
can me that. simon
i tried:
uiimage *image = [uiimage imagewithcontentsoffile: [[nsbundle mainbundle] pathforresource:@"play" oftype:@"png"]]; playbutton.image = image; uiimage *image = [uiimage imagewithcontentsoffile: [[nsbundle mainbundle] pathforresource:@"play" oftype:@"png"]];uiimage *image = [uiimage imagewithcontentsoffile: [[nsbundle mainbundle] pathforresource:@"play" oftype:@"png"]]; cgrect frame = cgrectmake(0, 0, image.size.width, image.size.height); uibutton* somebutton = [[uibutton alloc] initwithframe:frame]; [somebutton setbackgroundimage:image forstate:uicontrolstatenormal]; [somebutton setshowstouchwhenhighlighted:yes]; playbutton = [[uibarbuttonitem alloc]initwithcustomview:somebutton]; [somebutton release];
if want put image button use following code.
uiimage *image = [uiimage imagewithcontentsoffile: [[nsbundle mainbundle] pathforresource:@"play" oftype:@"png"]]; cgrect frame = cgrectmake(0, 0, image.size.width, image.size.height); uibutton* somebutton = [uibutton buttonwithtype:uibuttontypecustom]; [somebutton setbackgroundimage:image forstate:uicontrolstatenormal]; [somebutton setshowstouchwhenhighlighted:yes]; playbutton = [[uibarbuttonitem alloc]initwithcustomview:somebutton]; regards,
satya
Comments
Post a Comment