UIButton
来源:互联网 发布:金十数据dora是谁 编辑:程序博客网 时间:2024/06/05 04:13
//Button
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[_window makeKeyAndVisible];
UIView *view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
view.backgroundColor = [UIColor whiteColor];
[_window addSubview:view];
_button = [UIButton buttonWithType:UIButtonTypeSystem];
_button.frame = CGRectMake(50, 50, 200, 50);
_button.backgroundColor = [UIColor cyanColor];
//给button设置抬头
[_button setTitle:@"按我" forState:UIControlStateNormal];
// [_button setTitle:@"aaa" forState:UIControlStateHighlighted];
[_button setTitle:@"selected" forState:UIControlStateSelected];
_button.selected = YES;
//设置圆角
_button.layer.cornerRadius = 10; //layer 属性的属性
//加边框颜色
_button.layer.borderColor = [UIColor blackColor].CGColor;
//边框线宽
_button.layer.borderWidth = 0.5;
//
_button.titleLabel.font = [UIFont systemFontOfSize:Fontsize];
//标记
_button.tag = 101;
//设置抬头颜色
[_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//设置阴影颜色
[_button setTitleShadowColor:[UIColor redColor] forState:UIControlStateNormal];
//给button添加事件
[_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:_button];
#pragma mark button的响应事件
//参数
-(void)buttonAction:(UIButton *)sender{
//第1中方法(标记,父类)
// [(UIView *)(_window.subviews[0]) viewWithTag:101].backgroundColor = [UIColor redColor];
//第2中方法 属性
// _button.backgroundColor = [UIColor yellowColor];
//第3中方法 (调参数)
//sender.backgroundColor = [UIColor yellowColor];
//
CGFloat num1 = arc4random()%(255 - 1 + 1) + 1;
CGFloat num2 = arc4random()%(255 - 1 + 1) + 1;
CGFloat num3 = arc4random()%(255 - 1 + 1) + 1;
sender.backgroundColor = [UIColor colorWithRed:num1/255.0 green:num2/255.0 blue:num3/255.0 alpha:1];
}
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[_window makeKeyAndVisible];
UIView *view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
view.backgroundColor = [UIColor whiteColor];
[_window addSubview:view];
_button = [UIButton buttonWithType:UIButtonTypeSystem];
_button.frame = CGRectMake(50, 50, 200, 50);
_button.backgroundColor = [UIColor cyanColor];
//给button设置抬头
[_button setTitle:@"按我" forState:UIControlStateNormal];
// [_button setTitle:@"aaa" forState:UIControlStateHighlighted];
[_button setTitle:@"selected" forState:UIControlStateSelected];
_button.selected = YES;
//设置圆角
_button.layer.cornerRadius = 10; //layer 属性的属性
//加边框颜色
_button.layer.borderColor = [UIColor blackColor].CGColor;
//边框线宽
_button.layer.borderWidth = 0.5;
//
_button.titleLabel.font = [UIFont systemFontOfSize:Fontsize];
//标记
_button.tag = 101;
//设置抬头颜色
[_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//设置阴影颜色
[_button setTitleShadowColor:[UIColor redColor] forState:UIControlStateNormal];
//给button添加事件
[_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:_button];
#pragma mark button的响应事件
//参数
-(void)buttonAction:(UIButton *)sender{
//第1中方法(标记,父类)
// [(UIView *)(_window.subviews[0]) viewWithTag:101].backgroundColor = [UIColor redColor];
//第2中方法 属性
// _button.backgroundColor = [UIColor yellowColor];
//第3中方法 (调参数)
//sender.backgroundColor = [UIColor yellowColor];
//
CGFloat num1 = arc4random()%(255 - 1 + 1) + 1;
CGFloat num2 = arc4random()%(255 - 1 + 1) + 1;
CGFloat num3 = arc4random()%(255 - 1 + 1) + 1;
sender.backgroundColor = [UIColor colorWithRed:num1/255.0 green:num2/255.0 blue:num3/255.0 alpha:1];
}
0 0
- UIButton
- UIButton
- UIButton
- uibutton
- UIButton
- UIButton
- UIButton
- UIButton
- UIButton
- UIButton
- UIBUTTON
- UIButton
- UIButton
- UIButton
- UIBUTTON
- UIButton
- UIButton
- UIButton
- [20151019]SCZ训练
- Mysql学习 - 触发器和存储过程
- Java内存溢出详解及解决方案
- Problem H: 林教主的面试整数部分转换2进制,从右往左,除二取余;小数部分从左往右,乘二取整
- POJ 1251Jungle Roads(Kruskal)
- UIButton
- javascript入门
- iOS --- 使用CoreTelephony来获取运营商信息
- Java中的基本数据类型
- 黑马程序员 Java基础——多态、抽象类及接口
- Quick Sort源码
- 数学三角形问题
- Debugging Error: ClassNotFoundException的解决办法
- lintcode-落单的数III-84