iOS--UIButton的使用方法
2015-10-31 20:29
387 查看
UIButton的常用方法
//初始化时设置Button样式,个人喜欢用圆角样式 UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //UIButton的几种样式 //typedef NS_ENUM(NSInteger, UIButtonType) { // UIButtonTypeCustom = 0, // //no button type // UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), // //standard system button // UIButtonTypeDetailDisclosure, // UIButtonTypeInfoLight, // UIButtonTypeInfoDark, // UIButtonTypeContactAdd, // UIButtonTypeRoundedRect = UIButtonTypeSystem, // //Deprecated, use UIButtonTypeSystem instead //}; //设置button的位置和大小 button.frame = CGRectMake(50, 50, 100, 30); //设置button背景色 button.backgroundColor = [UIColor magentaColor]; //设置在什么状态下显示什么文字 [button setTitle:@"按钮" forState:UIControlStateNormal]; //设置在什么状态下字体什么颜色 [button setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal]; //设置背景图片 [button setBackgroundImage:[UIImage imageNamed:@"image.jpg"] forState:UIControlStateNormal]; //UIControlState的样式 // typedef NS_OPTIONS(NSUInteger, UIControlState) { // UIControlStateNormal = 0, // UIControlStateHighlighted = 1 << 0, // used when UIControl isHighlighted is set // UIControlStateDisabled = 1 << 1, // UIControlStateSelected = 1 << 2, // flag usable by app (see below) // UIControlStateApplication = 0x00FF0000, // additional flags available for application use // UIControlStateReserved = 0xFF000000 // flags reserved for internal framework use // }; //给button添加响应事件 [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; //添加到view [self.view addSubview:button];
//button的响应事件 - (void)buttonAction:(UIButton*)sender { NSLog(@"Hello world"); }
相关文章推荐
- IOS--UIScrollView和UIPageControl配合使用
- UISlider/UISegmentedControl/UISetpper/UISwitch/UIProgressView/UIPageControl/UIImageView
- iOS--UILabel的使用方法
- Maven: mvn -X 执行报错:No goals have been specified for this build.
- android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)
- DB表的关系及EF中Fluent API的使用
- 【从源码看Android】02MessageQueue的epoll原型
- Qt之统一的UI界面格式基调,漂亮的UI界面
- 【从源码看Android】03Android MessageQueue消息循环处理机制(epoll实现)
- OC UI学习中的笔记
- 杭电1159—Common Subsequence题解
- getRequestURI,getRequestURL的区别
- css3新UI
- True And False
- IOS 学习笔记之UI
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT
- 反射封装request参数为对象
- IOS笔记UI--进度条
- 【APUE】Chapter1 UNIX System Overview
- 【UI】锤子手机-坚果手机-文艺青年版-配色色号