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];

相关文章:

  • 2021-12-08
  • 2021-12-20
  • 2021-08-22
  • 2021-09-06
  • 2022-02-09
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-08-09
  • 2021-11-27
  • 2021-09-12
相关资源
相似解决方案