【代碼筆記】iOS-4個可以單獨點擊的button,ios-4button

來源:互聯網
上載者:User

【代碼筆記】iOS-4個可以單獨點擊的button,ios-4button

一,。

二,工程圖。

三,代碼。

ViewController.m

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        //初始化背景圖    [self addBackGroundView];    }#pragma -mark -functions//初始化背景圖-(void)addBackGroundView{    //4個連著的button    for (int i=0; i<4; i++) {                UIButton *chooseButton=[UIButton buttonWithType:UIButtonTypeCustom];        chooseButton.frame=CGRectMake(0+80*i,50, 80, 38);        chooseButton.tag=i;        if (i==0) {            [chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getno1"] forState:UIControlStateNormal];        }else if (i==1){            [chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getyes1"] forState:UIControlStateNormal];        }else if (i==2){            [chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workno1"] forState:UIControlStateNormal];        }else if (i==3){            [chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workyes1"] forState:UIControlStateNormal];        }        [chooseButton setBackgroundColor:[UIColor clearColor]];        [chooseButton addTarget:self action:@selector(doClickChooseButton:) forControlEvents:UIControlEventTouchUpInside];        [self.view addSubview:chooseButton];            }}#pragma -mark -doClickActions//4個按鈕-(void)doClickChooseButton:(UIButton *)btn{    NSLog(@"---doClickChooseButton--");    if (btn.tag==0) {        if (btn.selected==NO) {            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getno2"] forState:UIControlStateNormal];            btn.selected=YES;        }else{            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getno1"] forState:UIControlStateNormal];            btn.selected=NO;        }            }else if (btn.tag==1){        if (btn.selected==NO) {            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getyes2"] forState:UIControlStateNormal];            btn.selected=YES;        }else{            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getyes1"] forState:UIControlStateNormal];            btn.selected=NO;        }            }else if (btn.tag==2){        if (btn.selected==NO) {            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workno2"] forState:UIControlStateNormal];            btn.selected=YES;        }else{            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workno1"] forState:UIControlStateNormal];            btn.selected=NO;        }            }else if (btn.tag==3){        if (btn.selected==NO) {            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workyes2"] forState:UIControlStateNormal];            btn.selected=YES;        }else{            [btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workyes1"] forState:UIControlStateNormal];            btn.selected=NO;        }            }    }- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.