iOS第五章控件和动作(3)
//通过代码创建一个 Button
roundedButtonType= [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
//设置按钮的位置和尺寸,前两个参数设置 顶点坐标,后两个参数设置 宽、高
roundedButtonType.frame = CGRectMake(50.0, 250.0, 88.0 , 48.0);
//设置按钮的标题和状态
[roundedButtonType setTitle:@"Rounded" forState:UIControlStateNormal];
//设置按钮的背景颜色
roundedButtonType.backgroundColor = [UIColor clearColor];
//设置用户对 按钮进行何种操作,处理按钮事件的操作(回调函数)
[roundedButtonType addTarget:self
action:@selector(action:)
forControlEvents:UIControlEventTouchUpInside];
//设置按钮的编号,便于区分多个按钮
roundedButtonType.tag = 2;
需要单独为按钮事件处理编写方法,一般都叫 xxxAction:
- (void)action:(id)sender
{
//创建一个弹出提示框,
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"提示标题"
message:@"通过纯编码实现的按钮处理方法"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
//显示弹出提示框
[alert show];
}
------------------------------------------------------------------------------------------------------------------------------
自定义按钮
(1)创建带有图片的按钮
[myButton setImage:[UIImageimageNamed:@"myButtonImage.png"]
forState:UIControlStateNormal];
6、控制控件-开关 UISwitch
创建开关
初始化
CGRect switchRect = CGRectMake(120,50,0,0);
UISwitch *mySwitch = [[UISwitch alloc]initWithFrame:switchRect];
添加事件处理
[mySwitch addTarget: self
action:@selector(switchAction:)
forControlEvents: UIControlEventValueChanged];
切换开关
[mySwitch setOn:YES animated:YES];
修改开关外观
获得开关的两个Label
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- iphone-使用TextField及关闭键盘(useing TextField for in
- Cocoa Core Competencies 的Object creation 和IOS面试题示例
- iOS文件存磁盘的设想
- 深入理解iPhone静态库(手把手教你iphone开发
- iPhone开发 文件的增加删除查询
- ios 时间定时器 NSTimer应用demo
- (iOS-iap防护)验证用户付费收据,拒绝iap
- iPhone开发 调用阿asp.net程序的webservice
- ios 关于UITableView UITableViewCellAccessoryCheckmark 混乱的
- iphone开发基础三和c语言混编