1、创建按钮的两种方法:
·1、动态创建
btnfont = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnfont setFrame:CGRectMake(100, 10, 120, 40)];
[btnfont addTarget:self
action:nil
forControlEvents:UIControlEventTouchUpInside];
[btnfont setTitle:@"字体" forState:UIControlStateNormal];
btnfont.backgroundColor=[UIColor clearColor];
[self.view addSubview:btnfont];
·2、在xib文件中已经创建好,通过tag获取按钮
UIButton *testButton= (UIButton*)[self.view viewWithTag:100];
[testButton addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
2、
addAlarmBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[addAlarmBtn setFrame:CGRectMake(0, 892, 394, 71)];
[addAlarmBtn setTitle:@"添加闹钟" forState:UIControlStateNormal];
addAlarmBtn.titleLabel.font = [UIFont systemFontOfSize:26.0];//设置按钮上字体的大小
[addAlarmBtn addTarget:self
action:@selector(addAlarm:)
forControlEvents:UIControlEventTouchUpInside];
addAlarmBtn.backgroundColor = [UIColor yellowColor];
addAlarmBtn.alpha = 0.7f;
[self.view addSubview:addAlarmBtn];