iOS第五章控件和动作(3)

来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 10:58 点击:

 

//通过代码创建一个 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

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Lexical or Preprocessor Issue 'xxx.h
  • ios学习笔记(二)xcode 4.3.2下实现基本交互
  • ios版本的helloworld
  • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
  • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
  • IOS类似iphone通讯录TableView的完整demo【附源码】
  • UITableView一些方法
  • [iPhone中级]iPhone团购信息客户端的开发 (二)
  • 如何为Iphone应用创建启动界面
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1