iOS之Button以及警告视图(简单)

4 篇文章 0 订阅

 

    //创建一个button

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];

    button1.frame = CGRectMake(0, 0, 60, 40);

    button1.center = self.window.center;

    [button1 setTitle:@"弹出警告" forState:UIControlStateNormal];

    [button1 addTarget:self action:@selector(handleButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    [self.window addSubview:button1];

    

    UITextField *textFiel1 = [[UITextField alloc]initWithFrame:CGRectMake(20, 100, CGRectGetWidth(self.window.bounds) - 40, 50)];

    textFiel1.borderStyle =UITextBorderStyleRoundedRect;

    textFiel1.placeholder = @"哈哈哈";

    //修改键盘返回键的类型,textFild与键盘的联系紧密

    textFiel1.returnKeyType = UIReturnKeySend;

    //textField指定代理对象

    //text 设置了一个代理对象

    textFiel1.delegate = self;

    

    

    

    [self.window addSubview:textFiel1];

    [textFiel1 release];




实现为button添加的方法

- (void)handleButtonAction:(UIButton *)sender

{

    //创建一个警告视图

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示信息"

                                                           message:@"当前是一个警告信息"

                                                           delegate:self cancelButtonTitle:@"取消"

                                            otherButtonTitles:@"确定",@"哈哈",@"呵呵", nil];

    [alertView show];//显示警告视图

    [alertView release];

}



在这段代码里,只实现了几个小功能,添加了一个button,一个TextFiled,设置键盘的返回键形式,为button添加了一个点击方法,触发方法时,会弹出一个警告视图;

很简单~~~ 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值