按钮UIButton
来源:互联网 发布:问卷星可以分析数据吗 编辑:程序博客网 时间:2024/05/16 18:49
/*_____________________________UIButton_____________________________*/- (void)_initButton { //创建一个按钮// UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(220, 100, 60, 40)];// button.buttonType = UIButtonTypeRoundedRect; //不可以这么设置 //button只可以用过类方法设置类型 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(220, 100, 60, 40); //设置背景颜色// button.backgroundColor = [UIColor purpleColor]; //设置标题,他会和状态绑定 //设置普通状态的标题 [button setTitle:@"按钮" forState:UIControlStateNormal]; //设置高亮状态的标题 [button setTitle:@"点击中" forState:UIControlStateHighlighted]; //设置标题文字的字体 button.titleLabel.font = [UIFont systemFontOfSize:19]; //设置标题// button.titleLabel.text = @"text"; //不可取 //设置标题的字体颜色(和状态绑定) [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; [button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted]; button.tag = 100; //添加点击事件 /* UIControlEventTouchUpInside:在里面点击在里面松开 UIControlEventTouchDragInside:按着拖动触发事件 UIControlEventTouchDragOutside:在里面点击拖动到外面触发方法 UIControlEventTouchUpOutside:在里面点击后在外面松开 */ [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; //使用系统样式的按钮 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeInfoLight]; button1.tag = 101; button1.frame = CGRectMake(220, 160, 40, 40); [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button1]; }- (void)buttonAction:(UIButton *)button { if (button.tag == 100) { NSLog(@"按钮button被点击了"); }else if (button.tag == 101) { NSLog(@"按钮button1被点击了"); }else if (button.tag == 102) { NSLog(@"自定义按钮被点击了"); button.selected = !button.selected; }}//设置自定义图片的按钮- (void)_initCustomButton { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(220, 200, 80, 40); button.tag = 102; //创建显示的图片 UIImage *image1 = [UIImage imageNamed:@"back_on_black"]; UIImage *image2 = [UIImage imageNamed:@"back_on"]; //设置标题 [button setTitle:@"按钮" forState:UIControlStateNormal]; [button setTitle:@"点击中" forState:UIControlStateHighlighted]; //设置按钮的显示图片(注意:如果向设置标题,则用此种方法不能设置标题)// [button setImage:image1 forState:UIControlStateNormal];// [button setImage:image2 forState:UIControlStateHighlighted]; //设置标题的同时设置图片可以用以下方法 [button setBackgroundImage:image1 forState:UIControlStateNormal]; [button setBackgroundImage:image2 forState:UIControlStateSelected]; //添加点击事件 [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"禁用" forState:UIControlStateDisabled]; //设置按钮的禁用属性 button.enabled = NO; [self.view addSubview:button]; }
0 0
- UIButton----按钮
- UIButton----按钮
- 按钮UIButton
- UIButton/按钮
- UIButton - 按钮
- UIButton按钮控件
- UIButton按钮用法
- UIButton按钮控件
- UIButton按钮控件
- UIButton按钮控件
- 深度定制 UIButton 按钮
- 手动创建UIButton 按钮
- UIButton保存选中按钮
- 深度定制 UIButton 按钮
- UIButton 按钮控件
- UIButton 按钮 (孙子类)
- 深度定制 UIButton 按钮
- UIButton (常用点击按钮)
- 2014-10-27Android学习------布局处理(五)------ListView布局继续学习-----城市列表应用程序
- 注册表单
- 图片视图UIImageView
- 博客系统
- 2012年湖南省第八届程序设计大赛 J 病毒(最长上升公共子序列)
- 按钮UIButton
- MFC程序窗口标题设定
- ST nucleo系列在使用mbed时 bin文件的替代烧录方式
- 滑动条UISlider
- 数字电路设计之加法器的实现
- 1.16 24点游戏
- hibernate 延迟加载
- leetcode: Find Minimum in Rotated Sorted Array
- js 时间戳(毫秒级) 和 日期格式 (2011-12-13 01:45:30) 互转