IOS的基本控件的使用-警告对话框&等待提示器

 ViewController.h

//  警告对话框&等待提示器

//

//  Created by mac on 2016/10/28.

//  Copyright © 2016 mac. All rights reserved.

//


#import <UIKit/UIKit.h>


//  要使用alert的代理的时候再@interface ViewController : UIViewController后面加上<UIAlertViewDelegate>

@interface ViewController : UIViewController<UIAlertViewDelegate>

{

    //  定义一个警告对话框视图

    UIAlertView* _aleriView;

    

    //  定义等待提示对象

    //  当下载,或加载比较大的文件时,可以显示此控件

    //  处于提示等待状态

    UIActivityIndicatorView* _activityIndicator;


}


@property (retain , nonatomic) UIAlertView* aleriView;

@property (retain , nonatomic) UIActivityIndicatorView* activityIndicator;

@end


  ViewController.m

//  警告对话框&等待提示器

//

//  Created by mac on 2016/10/28.

//  Copyright © 2016 mac. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


@synthesize aleriView = _aleriView;

@synthesize activityIndicator = _activityIndicator;


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

   

    

    for (int i = 0; i<2; i++) {

        UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        

        btn.frame = CGRectMake(100, 100+100*i, 100, 40);

        

        if (i == 0) {

            [btn setTitle:@"警告对话框" forState:UIControlStateNormal];

        }

        else{

            [btn setTitle:@"等待指示器" forState:UIControlStateNormal];

        }

        

        btn.tag= 101 + i;

        

        [btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:btn];

    }

}

-(void) pressBtn: (UIButton*) btn

{

    //  创建警告对话框

    if(btn.tag == 101)

    {

        //  创建警告对话框

        //  p1:对话框标题

        //  p2:提示信息

        //  p3:处理按钮时间的代理对象

        //  p4:取消按钮的文字

        //  p5:其他按钮的文字

        //  p6.....:添加其他按钮

        //  Plast:表示按钮添加结束

        

        

         _aleriView = [[UIAlertView alloc] initWithTitle:@"警告"

                                       message:@"你的手机电量过低,即将关机,请保存好数据"

                                       delegate:self

                                       cancelButtonTitle:@"取消"

                                       otherButtonTitles:@"OK", @"as",@"sad",nil];

        //  显示对话框

        [_aleriView show];

    }

    //  创建等待提示器

    else if (btn.tag == 102)

    {

        //  宽度高度不可变更

        _activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 300, 80, 80)];

        

        //  设置提示风格:小灰,小白,大白

        _activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;

        

        //

        [self.view addSubview:_activityIndicator];

        

        //  启动动画并且显示

        [_activityIndicator startAnimating];

        

        //  停止等待动画并隐藏

        // [_activityIndicator stopAnimating];

    }

}


//  当点击对话框的按钮时,调用此函数

//  p1:对话框对象本身

//  p2:按钮的索引

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    NSLog(@"indes = %ld/n",buttonIndex);

}


//  对话框消失,此函数调用

-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

{

    NSLog(@"即将消失");

}


//  对话框已经消失时,调用此函数

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

{

    NSLog(@"已经消失");

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值