【原】UIButton使用汇总

简介:

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

本文转自编程小翁博客园博客,原文链接:http://www.cnblogs.com/wengzilin/archive/2012/03/18/2404587.html,如需转载请自行联系原作者

相关文章
|
iOS开发
iOS开发 - UITableView的tableHeaderView注意事项(遮挡cell,内容重复等等)
iOS开发 - UITableView的tableHeaderView注意事项(遮挡cell,内容重复等等)
265 0
|
Swift
Swift - 如何让UIView,UILabel和UIImageView之间类型互相转化
Swift - 如何让UIView,UILabel和UIImageView之间类型互相转化
114 0
通过UIView对象获取该对象所属的UIViewController
通过UIView对象获取该对象所属的UIViewController
65 0