iphone - Change UIButton background images randomly -


i want change background image of uibutton randomly. have images (5) want switch between randomly background images uibutton. how can implement this? please me out problem.

how

nsinteger randomnumber =  arc4random_uniform(5); // random number, either 0,1,2,3 or 4 uiimage *randomimage = [uiimage imagenamed:[nsstring stringwithformat:@"img%u.png",randomnumber]];  //uibutton *mybutton; [mybutton setbackgroundimage:randomimage forstate:uicontrolstatenormal]; 

alternate solution perhaps easier understand

nsinteger randomnumber =  arc4random_uniform(5); // random number, either 0,1,2,3 or 4 uiimage *randomimage;  switch (randomnumber) {     case 0:         randomimage = [uiimage imagenamed:@"img0.png"];         break;     case 1:         randomimage = [uiimage imagenamed:@"img1.png"];         break;     case 2:         randomimage = [uiimage imagenamed:@"img2.png"];         break;     case 3:         randomimage = [uiimage imagenamed:@"img3.png"];         break;     case 4:         randomimage = [uiimage imagenamed:@"img4.png"];         break;     default:         break; } //uibutton *mybutton; [mybutton setbackgroundimage:randomimage forstate:uicontrolstatenormal]; 

for future reference; should not ask question more or less ask solve problems you. include have tried if have pseudo code.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -