iOS开发笔记之三十一——UIButton的使用总结

来源:互联网 发布:画漫画软件sai 编辑:程序博客网 时间:2024/06/10 20:43

1、基本属性
    //设置UIButton标题:
    [button setTitle:@"title" forState:UIControlStateNormal];
    //设置UIButton标题颜色:
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //设置UIButton背景图片和填充图片:
    [button setBackgroundImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal];
    //设置UIButton背景颜色:
    button.backgroundColor = [UIColor clearColor];
    //设置UIButton按钮字体的大小:
    button.titleLabel.font = [UIFont systemFontOfSize:26.0];//设置按钮上字体的大小
    [button setTintColor:[UIColor whiteColor]];

2、button添加点击事件

    [button addTarget:self action:@selector(onAction) forControlEvents:UIControlEventTouchUpInside];

      addTarget:self 是链接到self,一般都这样设置
      action:@selector(alarmTimeDone:) 时间处理函数
      forControlEvents:UIControlEventTouchUpInside 控件事件处理的消息

     删除点击事件,用下面方法:

 - (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

3、image与title属性的设置。。


4、未完待续。。

0 0