码迷,mamicode.com
首页 > 其他好文 > 详细

UIButton的使用

时间:2015-11-22 13:45:42      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor grayColor];
    button.frame = CGRectMake(10, 20, 80,80);
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    button.tag = 1;
    [self.view addSubview:button];
   
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.backgroundColor = [UIColor grayColor];
    button1.frame = CGRectMake(10, 110, 80,80);
    [button1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    button1.tag = 2;
    [self.view addSubview:button1];
   
   
    _label = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, 200, 20)];
    [self.view addSubview:_label];
   
}

-(void)buttonClicked:(UIButton *)btn{
    _label.text = [NSString stringWithFormat:@"%zi",btn.tag];
    NSLog(@"按钮%zi被点击",btn.tag);
}

UIButton的使用

标签:

原文地址:http://www.cnblogs.com/banchuangshuying/p/4985622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!