首页 > 其他 > 详细

UIButton的使用

时间:2015-11-22 13:44:32      阅读:273      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!