iphone - How to customize Buttons in UIActionSheet? -


i want change image of buttons of uiactionsheet, have images each button, , want each button show image want. searched web found lot of answers didn't work.

here initialization of uiactionsheet

-(ibaction)showactionsheet:(id)sender {      uiactionsheet *popupquery = [[uiactionsheet alloc] initwithtitle:@"title" delegate:self cancelbuttontitle:@"cancel button" destructivebuttontitle:nil otherbuttontitles:@"other button 1", @"other button 2", nil];     popupquery.actionsheetstyle = uiactionsheetstyledefault;     [popupquery showinview:self.view];     [popupquery release];  } 

i create subclass customactionsheet derived uiactionsheet, , implement method called customizegui.

use customactionsheet uiactionsheet, except must call method customizegui of subclass in willpresentactionsheet delegate:

- (void)willpresentactionsheet:(uiactionsheet *)actionsheet {     if ([actionsheet iskindofclass:[customactionsheet class]]) {         customactionsheet *sheet = (customactionsheet*)actionsheet;         [sheet customizegui];     } } 


(customactionsheet.m)

- (void)customizegui {     uiimageview *imgvwbackground = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"bg_actionsheet.png"]];     cgrect rect = self.bounds;     imgvwbackground.frame = rect;     [self insertsubview:imgvwbackground atindex:0];     [imgvwbackground release];      int buttonindex = 0;     uiimage *imgbuttondestructive = [uiimage imagenamed:@"btn_actionsheet_destructive.png"];     uiimage *imgbuttoncancel = [uiimage imagenamed:@"btn_actionsheet_cancel.png"];     uiimage *imgbuttonnormal = [uiimage imagenamed:@"btn_actionsheet_normal.png"];     (uiview *sub in self.subviews) {         nsstring *classname = [nsstring stringwithformat:@"%@", [sub class]];         if ( ([classname isequaltostring:@"uithreepartbutton"]) //ios 4             || ([classname isequaltostring:@"uialertbutton"]) ) { //ios 5             rect = sub.frame;             sub.hidden = yes;              uibutton *btn = [[uibutton alloc] initwithframe:rect];             uiimage *imgforbutton = nil;             if (buttonindex == self.cancelbuttonindex) {                 imgforbutton = imgbuttoncancel;             }             else if (buttonindex == self.destructivebuttonindex) {                 imgforbutton = imgbuttondestructive;             }             else {                 imgforbutton = imgbuttonnormal;             }             nsstring *stitle = [self buttontitleatindex:buttonindex];             btn.titlelabel.font = [uifont boldsystemfontofsize:19];             [btn setbackgroundimage:imgforbutton forstate:uicontrolstatenormal];             [btn settitle:stitle forstate:uicontrolstatenormal];             btn.tag = buttonindex;             [btn addtarget:self action:@selector(buttonclicked:) forcontrolevents:uicontroleventtouchupinside];              [self addsubview:btn];             [btn release];              buttonindex++;         }     } }  - (void)buttonclicked:(id)sender {     uibutton *btn = sender;     if ([self.delegate respondstoselector:@selector(actionsheet:clickedbuttonatindex:)]) {         [self.delegate actionsheet:self clickedbuttonatindex:btn.tag];     }     [self dismisswithclickedbuttonindex:btn.tag animated:yes]; } 

hope way can , give idea customize uiactionsheet


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -