UIButton常用属性小结(编辑中。。。)
Button的功能很黄很暴力,即能显示文字,又能显示图片,还能随时调整内部图片和文字的位置,用的地方很多。
(1)按钮常用的四种状态:
normal(普通状态)
默认情况(Default)
对应的枚举常量:UIControlStateNormal
highlighted(高亮状态)
按钮被按下去的时候(手指还未松开)
对应的枚举常量:UIControlStateHighlighted
selected (选中状态)
选没选中由我们自行设定
对应的枚举常量:UIControlStateSelected
disabled(失效状态,不可用状态)
如果enabled属性为NO,就是处于disable状态,代表按钮不可以被点击
对应的枚举常量:UIControlStateDisabled
(2)创建button:+ (id)buttonWithType:(UIButtonType)buttonType;
typedef NS_ENUM(NSInteger, UIButtonType) {
UIButtonTypeCustom = 0, // no button type
UIButtonTypeSystem, // standard system button
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
常用的是UIButtonTypeCustom和UIButtonTypeSystem,一般选用UIButtonTypeSystem,当你需要对button进行一些个性化的设置时,比如button的选中状态与未选中状态,字体,图片这些不同时,就必须要选择UIButtonTypeCustom,不然,选中状态时,按钮的上面会出现一个蓝色的竖条条。
UIButtonTypeRoundedRect = UIButtonTypeSystem, // Deprecated, use UIButtonTypeSystem instead
};
(2)按钮的常用属性
Button.titleLabel.font = [UIFont systemFontOfSize:20]; //改变button字体大小
(3)button的描边
(4)button的四角设置弧度
(5)
(6)
(7)
(8)
(9)
(10)
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 200, 100);
//[button setTitle:@"呵呵..." forState:UIControlStateNormal];
//button.backgroundColor = [UIColor lightGrayColor];
//[button setTintColor:[UIColor yellowColor]];
button.titleLabel.text = @"hehe";
button.showsTouchWhenHighlighted=YES;
[button addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];
//将标签加入视图
[self.view addSubview:button];
}
-(void)addButton:(UIButton*)button{
button.selected = !button.selected;
if (button.selected) {
NSLog(@"selected");
button.backgroundColor = [UIColor lightGrayColor];
[button setTitle:@"点我干嘛!" forState:UIControlStateNormal];
NSLog(@"%@",button.currentTitle);
} else {
NSLog(@"unSelected");
[button setTitle:@"呵呵..." forState:UIControlStateNormal];
NSLog(@"%@",button.currentTitle);
}
}
---恢复内容结束---
UIButton常用属性小结(编辑中。。。)的更多相关文章
- UILabel常用属性小结
标签常用的属性: (1)frame属性:设置标签的位置与大小. frame = CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat heig ...
- 【iOS】UIButton 常用属性
发现 UIButton 的相关属性不熟悉了……常用的一些属性代码如下: UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom]; ad ...
- IOS UIButton常用属性
//1.添加按钮 UIButton *nameView=[UIButton buttonWithType:UIButtonTypeCustom]; //nameView.backgroundColor ...
- Swift2.0 中的String(一):常用属性
字符串算是平常用的比较多.花样也比较多的一个类型,昨天有空把相关的一些常用操作都写了一遍,总结出来.其实iOS里面的字符串更复杂,还有NSString系列等等,那些API太多将来需要用的时候再慢慢学. ...
- 给iOS开发新手送点福利,简述UIButton的属性和用法
UIButton属性 1.UIButton状态: UIControlStateNormal // 正常状态 UIControlStateHighlighted // 高 ...
- UIButton的常用属性
可以通过代码的方式创建UIButton 通用实例化对象方法: UIButton *button = [[UIButton alloc] initWithFrame:rect]; 快速实例化对象方法: ...
- DataGrid中的常用属性
DataGrid中的常用属性 $('#dg').datagrid({ url:'datagrid_data.json', columns:[[ {field:'code',title:'Code',w ...
- Android开发中XML布局的常用属性说明
<!-- 常用属性说明: android:id="@+id/button" 为控件指定Id android:text="NNNNNNNNNN" 指定控件的 ...
- Delphi中TStringList类常用属性方法详解
TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 先把要讨论的几个属性列出来: 1.CommaText 2.Delim ...
随机推荐
- ActionBar的简单使用
只简单实现了一下ActionBar的使用,在右上角添加两个ActionBar,在左上角实现默认的返回箭头,类似于微信朋友圈的 这是MainActivity的代码: public class MainA ...
- typedef void far *LPVOID 的具体定义
首先这里的far,在32位系统已经废除不用了.它是C/C++语言在16位系统中用以标明指针是个远指针的修饰符. 远指针是说指针所指向的地址已经超出了64K(2的十六次方),所以需要使用DS加偏移量的方 ...
- 使用nodejs的net模块创建TCP服务器
使用nodejs的net模块创建TCP服务器 laiqun@msn.cn Contents 1. 代码实现 2. 使用telnet连接服务器测试 3. 创建一个TCP的client 1. 代码实现 ; ...
- Xcode如何简单安装Alcatraz
1.最简单直接,直接到github获取该项目 地址:www.github.com,搜索Alcatraz: 2.通过Xcode打开该项目,编译success后,退出Xcode,再启动,再弹出框选择loa ...
- Android蓝牙传感应用(转)
源:http://www.cnblogs.com/xiaochao1234/p/3753538.html Android手机一般以客户端的角色主动连接SPP协议设备(接上蓝牙模块的数字传感器),连接流 ...
- fiddler2 中文乱码问题
打开注册表编辑器,找到HKCU\Software\Microsoft\Fiddler2\,在里面添加一个字符串值,名叫HeaderEncoding,值设置为默认编码.建议设成GB18030.然后要记得 ...
- zf-安徽桐城关于(资源中心-数据录入)上传文件后没有进行处理Excel文件的原因
上传的文件 是会自动复制到另外一个路径的 如果没有进行处理 那么表示那个路径并没有那个文件 这样就会卡死 导致之后的文件都不会进行处理(后台有个变量是从数据库里获得文件路径的),所以需要去数据库 执行 ...
- 【学生成绩管理系统】 大二c语言作业
几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...
- windows编程:创建DLL
创建DLL Dll是动态链接库的缩写,可以作为附加代码动态映射到进程的地址空间中. 动态库的一般创建方法如下 方法1.使用 __declspec(dllexport) 方式导出 一般的框架如下 // ...
- Java笔记(三)
12. 字符串 String s1 = "abc"; String s2 = new String("abc"); s1在内存中有一个对象:s2在内存中有两个对 ...