UIButton及其方法

来源:互联网 发布:音频频谱分析软件 编辑:程序博客网 时间:2024/06/05 18:20

// UIButton
// 点击按钮视图

// 1.Button用便利构造器创建时,不需要释放// 2.currentTitle 当前的标题// 3.current 当前的// 1.创建一个Button方式同UIView 1 ~ 4// 2.添加边框 弧度button.layer.borderWidth = 1;button.layer.cornerRadius = 10;// 3.添加一个标题[button setTitle:@"确认" forState:UIControlStateNormal];// 4.修改字体大小button.titleLabel.font = [UIFont systemFontOfSize:25];// 5.修改颜色[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];// 6.放置一个图片作为buttonUIButton *bu = [UIButton buttonWithType:UIButtonTypeSystem];[bu setBackgroundImage:[UIImage imageNamed:@"文件名"] forState:UIControlStateNormal];// 7.给button添加一个事件 (用触发button点击 去调用一个方法)[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];// 实现一个点击后 使button改变字符的方法- (void)click:(UIButton *)button {    // 如果button 当前的标题是确认    if ([button.currentTitle isEqualToString:@"确认"]) {        // 把button的标题设为取消 在控件正常状态时        [button setTitle:@"取消" forState:UIControlStateNormal];        // 否则    } else {        // 把button的标题设为确认 在控件正常状态时        [button setTitle:@"确认" forState:UIControlStateNormal];    }}
0 0
原创粉丝点击