//1.按钮类uibuttom的使用方法
//1.1按钮类的基本使用
//UIButton *buttom=[[UIButton alloc]init];
//一般情况下都使用类方法去创建
// standard system button
//UIButtonTypeCustom = 0, //图片按钮
//UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0) //系统按钮
//UIButtonTypeRoundedRect = UIButtonTypeSystem, //圆角矩形
UIButton *buttom=[UIButton buttonWithType:UIButtonTypeSystem];
buttom.frame=CGRectMake(100, 200, 100, 40);
//设置显示的文本
//按钮有三种常用状态( 正常,高亮,禁用);
[buttom setTitle:@"来点我呀" forState:UIControlStateNormal];
[self.window addSubview:buttom];
//iOS 6 上默认都是圆角矩形,
//iOS 7扁平化
//告诉按钮被点后应该执行那个方法
//forControlEvents 控件事件类型
//action
[buttom addTarget:self action: @selector(btn_Click:) forControlEvents:UIControlEventTouchUpInside];
//1.2.设置文本的颜色
[buttom setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//1.3.设置字体
buttom.titleLabel.font=[UIFont systemFontOfSize:20];
//1.4.禁用按钮
//buttom.enabled=NO;
//1.5.按钮被点击高亮效果
buttom.showsTouchWhenHighlighted=YES;
//6tag 每个控件都有tag
//区分不同的控件
buttom.tag=100;
//1.6 圆角矩形
button.layer.cornerRadius=5;
//2 实现一个带图片的按钮
UIButton *imagebuttom=[UIButton buttonWithType:UIButtonTypeCustom];
imagebuttom.frame=CGRectMake(100, 300, 100,30);
//按钮添加北京图片
//使用的图片资源烤入工程
//创建图片对象
UIImage *image=[UIImage imageNamed:@"back.png"];
//设置按钮的背景为图片
[imagebuttom setBackgroundImage:image forState:UIControlStateNormal];
[self.window addSubview:imagebuttom];
//给imagebuttom添加点击事件
[imagebuttom addTarget:self action: @selector(btn_Click:) forControlEvents:UIControlEventTouchUpInside];
[imagebuttom setTitle:@"继续点我啊" forState:UIControlStateNormal];
//设置文本左边的图片
[imagebuttom setImage:[UIImage imageNamed:@"logo.png"] forState:UIControlStateNormal];
//设置按钮中图片和文本的位置
//top left buttom right
imagebuttom.imageEdgeInsets=UIEdgeInsetsMake(0, 50, 0, 0);
//文本的位置
imagebuttom.titleEdgeInsets=UIEdgeInsetsMake(0, -30, 0, 0);
//为按钮添加一个事件处理方法
//参数是固定的,参数是事件的来源
-(void)btn_Click:(UIButton*)buttom
{
//弹出消息对话框
UIAlertView *alert=[[UIAlertView alloc]init];
alert.message=@"我被点击了";
[alert addButtonWithTitle:@"取消"];
[alert show];
}
//1.1按钮类的基本使用
//UIButton *buttom=[[UIButton alloc]init];
//一般情况下都使用类方法去创建
// standard system button
//UIButtonTypeCustom = 0, //图片按钮
//UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0) //系统按钮
//UIButtonTypeRoundedRect = UIButtonTypeSystem, //圆角矩形
UIButton *buttom=[UIButton buttonWithType:UIButtonTypeSystem];
buttom.frame=CGRectMake(100, 200, 100, 40);
//设置显示的文本
//按钮有三种常用状态( 正常,高亮,禁用);
[buttom setTitle:@"来点我呀" forState:UIControlStateNormal];
[self.window addSubview:buttom];
//iOS 6 上默认都是圆角矩形,
//iOS 7扁平化
//告诉按钮被点后应该执行那个方法
//forControlEvents 控件事件类型
//action
[buttom addTarget:self action: @selector(btn_Click:) forControlEvents:UIControlEventTouchUpInside];
//1.2.设置文本的颜色
[buttom setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//1.3.设置字体
buttom.titleLabel.font=[UIFont systemFontOfSize:20];
//1.4.禁用按钮
//buttom.enabled=NO;
//1.5.按钮被点击高亮效果
buttom.showsTouchWhenHighlighted=YES;
//6tag 每个控件都有tag
//区分不同的控件
buttom.tag=100;
//1.6 圆角矩形
button.layer.cornerRadius=5;
//2 实现一个带图片的按钮
UIButton *imagebuttom=[UIButton buttonWithType:UIButtonTypeCustom];
imagebuttom.frame=CGRectMake(100, 300, 100,30);
//按钮添加北京图片
//使用的图片资源烤入工程
//创建图片对象
UIImage *image=[UIImage imageNamed:@"back.png"];
//设置按钮的背景为图片
[imagebuttom setBackgroundImage:image forState:UIControlStateNormal];
[self.window addSubview:imagebuttom];
//给imagebuttom添加点击事件
[imagebuttom addTarget:self action: @selector(btn_Click:) forControlEvents:UIControlEventTouchUpInside];
[imagebuttom setTitle:@"继续点我啊" forState:UIControlStateNormal];
//设置文本左边的图片
[imagebuttom setImage:[UIImage imageNamed:@"logo.png"] forState:UIControlStateNormal];
//设置按钮中图片和文本的位置
//top left buttom right
imagebuttom.imageEdgeInsets=UIEdgeInsetsMake(0, 50, 0, 0);
//文本的位置
imagebuttom.titleEdgeInsets=UIEdgeInsetsMake(0, -30, 0, 0);
//为按钮添加一个事件处理方法
//参数是固定的,参数是事件的来源
-(void)btn_Click:(UIButton*)buttom
{
//弹出消息对话框
UIAlertView *alert=[[UIAlertView alloc]init];
alert.message=@"我被点击了";
[alert addButtonWithTitle:@"取消"];
[alert show];
}