ios - how to add UIImage from a NSMutableArray of images to UIButton using setImage -
i have array of uiimages have created this
uiimage *tbuttonimage = [uiimage imagenamed:@"button-measurement.png"]; uiimage *tpbuttonimage = [uiimage imagenamed:@"button-parts.png"]; uiimage *opbuttonimage = [uiimage imagenamed:@"button-onboard.png"]; uiimage *dbuttonimage = [uiimage imagenamed:@"button-opening.png"];
// depending on corresponding values of nsdicitonary / keyvalue pairs decide uiimages put array so
nsmutablearray *arrayofbuttonimages = [[nsmutablearray alloc] init]; if ([hasinfosetidstring isequaltostring:@"t"]) { [arrayofbuttonimages addobject:tbuttonimage]; } if ([hastsetidstring isequaltostring:@"t"]) { [arrayofbuttonimages addobject:tpbuttonimage]; } if ([hasosetidstring isequaltostring:@"t"]) { [arrayofbuttonimages addobject:opbuttonimage]; } if ([hasdsetidstring isequaltostring:@"t"]) { [arrayofbuttonimages addobject:dbuttonimage]; }
by point depending on values in nsdictionary might have array looks this.
nslog(@"%@", arrayofbuttonimages); ( "<uiimage: 0x2001f4c0>", "<uiimage: 0x1ed51c20>" )
i try apply images buttons have, buttons "dynamic" per say.
if (arrayofbuttonimages != nil) { (int = 0; < [arrayofbuttonimages count]; i++) { if (i == 0) { [jumpbutton1p setimage:[arrayofbuttonimages objectatindex:i] forstate:uicontrolstatenormal]; } else if (i == 1) { [jumpbutton2p setimage:[arrayofbuttonimages objectatindex:i] forstate:uicontrolstatenormal]; } else if (i == 2) { [jumpbutton3p setimage:[arrayofbuttonimages objectatindex:i] forstate:uicontrolstatenormal]; } else if (i == 3) { [jumpbutton4p setimage:[arrayofbuttonimages objectatindex:i] forstate:uicontrolstatenormal]; } else if (i == 4) { [jumpbutton5p setimage:[arrayofbuttonimages objectatindex:i] forstate:uicontrolstatenormal]; } } }
so after said , done, image not appearing on uibutton.. have checked make sure uibutton variable connected uibutton object in interface builder.. still going wrong.
i have tried simple
uiimage *btnimage1 = [uiimage imagenamed:@"diagram-p.png"]; [jumpbutton1p setimage:btnimage1 forstate:uicontrolstatenormal];
and dosnt work.
hopefully makes sense.. appreciated.
try setting backgroundimage instead:
[jumpbutton1p setbackgroundimage:[uiimage imagenamed:@"diagram-p"] forstate:uicontrolstatenormal];
Comments
Post a Comment