UIButton *but = [[UIButton alloc]init];
but.frame = CGRectMake(30, 30, 100, 100);
//设置button的颜色
//but.backgroundColor = [UIColor redColor];
//设置button上显示的字的颜色
[but setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//设置button上显示的字
//but.titleLabel.text = @"按钮";
//这是在未点击状态下
[but setTitle:@"按钮" forState:UIControlStateNormal ];
//设置字体大小
but.titleLabel.font = [UIFont boldSystemFontOfSize:20];
//设置背景图片,标题在背景图上
//[but setBackgroundImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
// [but setBackgroundImage:[UIImage imageNamed:@"2"] forState:UIControlStateHighlighted];
//标题在背景图左边
[but setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
[but setImage:[UIImage imageNamed:@"2"] forState:UIControlStateHighlighted];
but.imageEdgeInsets = UIEdgeInsetsMake(0, 30, 0, 0);
//设置按钮的圆角半径不会被遮挡
[but.layer setMasksToBounds:YES];
//设置圆角的半径
[but.layer setCornerRadius:30];
//设置边界的宽度
[but.layer setBorderWidth:1];
[self.view addSubview:but];
-(void)buttonClicked:(UIButton *)btn{
_label.text = [NSString stringWithFormat:@"%zi",btn.tag];
NSLog(@"按钮%zi被点击",btn.tag);