iOS开发中UIButton的使用方法总结
来源:互联网 发布:淘宝虚假交易如何挽救 编辑:程序博客网 时间:2024/05/21 22:30
iOS开发中UIButton的使用方法总结
Button即为按钮,UIButton是app开发中使用频繁的控件之一.UIButton继承于UIControl:UIView的:UIResponder:NSObject的.以下是我对UIButton的解析:
1). 创建一个button的两种方法
1. 类方法 initWithType
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
风格有如下
typedef enum {
UIButtonTypeCustom = 0, //no button type 自定义,无风格
UIButtonTypeRoundedRect, // 白色圆角矩形
UIButtonTypeDetailDisclosure, // 蓝色的披露按钮,可放在任何文字旁
UIButtonTypeInfoLight, // 微件使用的小圆圈信息按钮,可以放在任何文字旁
UIButtonTypeInfoDark, // 白色背景下使用的深色圆圈信息按钮
UIButtonTypeContactAdd, // 蓝色加号(+)按钮,可以放在任何文字旁
} UIButtonType;
2. initWithFrame
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 50, 50)];
// 这种方法直接初始化了button的Frame属性,完成操作button操作后 需要 [button release]; 来保持引用 计数平衡.
2). UIButton的属性及方法
1.Frame属性,指定button 的位置和大小
button.frame = CGRectMake(20, 20, 50, 50);
2.给button添加背景颜色
button.backgroundColor = [UIColor clearColor];
3.给button设置标签,用来辨别点击的是哪个button
button.tag = 0;
4.定义按钮标题
[button setTitle:@“点击”forState:UIControlStateNormal];
5.定义按钮标题字体格式
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
6.将button加入视图当中
[view addSubview:button];
7.给button添加点击触发事件
[button addTarget:self action:@selector(buttonAction:) forControlEvents :UIControl EventTouchUp Inside];
- (void)buttonAction:(id)sender
{
UIButton * button = (UIButton *)sender;
// 开始写自己的行为
}
8.将button加入视图当中
[view addSubview:button];
9.给button添加图片
[button setImage:[UIImage imageNamed:@“a.jpg”] forState:UIControlStateNormal];
10.设置标题颜色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
11.阴影
[button setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal ];
上面三个方法都提到共同的参数 forState .这个参数决定了标题、图像或其他属性将在何种状态下显现:
enum{
UIControlStateNormal = 0, //常态
UIControlStateHighlighted = 1 << 0, // 高亮
UIControlStateDisabled = 1 << 1, //禁用
UIControlStateSelected = 1 << 2, //选中
UIControlStateApplication = 0x00FF0000, //当应用程序标志使用时
UIControlStateReserved = 0xFF000000 //为内部框架预留的
};
- iOS开发中UIButton的使用方法总结
- iOS--UIButton的使用方法
- iOS - UIButton 开发总结
- iOS--UIButton的使用方法详细
- IOS--UIButton的使用方法详细
- IOS UIButton的属性总结
- ios开发-UIButton的学习
- iOS开发中UIButton的setImage和setBackgroundImage用法区别
- UIButton 使用方法心得总结
- iOS中UIButton的block
- iOS中UIButton的使用
- ios中UIButton的使用
- iOS中UIWebView的科学使用方法总结
- iOS开发-UIButton中title位置设置
- iOS开发中UICollectionView的使用方法
- ios学习总结(2) -- UIButton的使用
- iOS UILabel UIButton UIImageView使用方法
- UIButton的一些使用方法
- 从零开始做游戏 - 膝盖中了一箭
- ZOJ Problem Set - 2818 Root of the Problem
- 关于界面弹出框的问题
- 从零开始做游戏 - 超级玛丽30年
- Elasticsearch集群安装与使用
- iOS开发中UIButton的使用方法总结
- 树莓派Samba服务器学习笔记
- HDOJ 2044 一只小蜜蜂
- POJ 3384 Feng Shui
- POJ 2528 Mayor's posters(线段树离散化)
- 关于win8桌面应用程序闪退(不能打开)的解决过程
- Linux系统开发:文件的i节点
- Qt QString的用法
- N-Queens