Loop BTN The above view

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.