#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Whitecolor]; UIButton* BTN = [self Createbtn:yes andcgrectmake:cgrectmake ( -, -, -, -)]; [BTN Settitle:@"length"Forstate:uicontrolstatenormal]; [Btn addtarget:self Action: @selector (PRESSBTN:) forcontrolevents:uicontroleventtouchupinside]; Btn.backgroundcolor=[Uicolor Cyancolor]; Btn.tag=1; [Self.view ADDSUBVIEW:BTN]; UIButton* BTN1 = [self Createbtn:yes andcgrectmake:cgrectmake ( -, -, -, -)]; Btn1.tag=2; Btn1.selected=NO; [Btn1 settitle:@"Length Length"Forstate:uicontrolstatenormal]; //the background picture of the loop btn BTN cannot be changed /*Uiimageview * image = [[Uiimageview alloc]init]; Image.backgroundcolor = [Uicolor Orangecolor]; Uiimageview * Image1 = [[Uiimageview alloc]init]; Image1.backgroundcolor = [Uicolor Yellowcolor]; [Btn1 setImage:image.image Forstate:uicontrolstatenormal]; [Btn1 setImage:image1.image forstate:uicontrolstateselected];*/[btn1 Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstateselected]; [Btn1 Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal]; [Btn1 addtarget:self Action: @selector (PRESSBTN:) forcontrolevents:uicontroleventtouchupinside]; Btn1.backgroundcolor=[Uicolor Cyancolor]; [Self.view addsubview:btn1];}-(void) Pressbtn: (uibutton*) sender{ // cycle btn btn background picture cannot be changed if(Sender.tag = =1) { for(IDObjinchsender.subviews) {if([obj Iskindofclass:[uiimageviewclass]]) { if(sender.selected) {Uiimageview* Image = (uiimageview*) obj; Image.backgroundcolor=[Uicolor Redcolor]; Sender.selected=NO; } Else{Uiimageview* Image = (uiimageview*) obj; Image.backgroundcolor=[Uicolor Graycolor]; Sender.selected=YES; } } } } Else{ for(IDObjinchsender.subviews) {if([obj Iskindofclass:[uiimageviewclass]]) { if(sender.selected) {Uiimageview* Image = (uiimageview*) obj; Image.backgroundcolor=[Uicolor Redcolor]; Sender.selected=NO; } Else{Uiimageview* Image = (uiimageview*) obj; Image.backgroundcolor=[Uicolor Graycolor]; Sender.selected=YES; } } } }}-(uibutton*) Createbtn: (BOOL) Yes Andcgrectmake: (cgrect) frame{UIButton* BTN =[UIButton Buttonwithtype:uibuttontypecustom]; Btn.frame=frame; Uiimageview*image = [[Uiimageview alloc]initwithframe:cgrectmake (btn.titlelabel.frame.size.width/2+btn.frame.size.width/2+ -, -, -, -)]; Image.backgroundcolor=[Uicolor Redcolor]; [Btn Addsubview:image]; returnbtn; }
Loop BTN The above view