UI5_UIAlertView与UIActionSheet

//

//  ViewController.h

//  UI5_UIAlertView与UIActionSheet

//

//  Created by zhangxueming on 15/7/7.

//  Copyright (c) 2015年 zhangxueming. All rights reserved.

//



#import <UIKit/UIKit.h>



@interface ViewController : UIViewController <UIAlertViewDelegate,UIActionSheetDelegate>







@end







//

//  ViewController.m

//  UI5_UIAlertView与UIActionSheet

//

//  Created by zhangxueming on 15/7/7.

//  Copyright (c) 2015年 zhangxueming. All rights reserved.

//



#import "ViewController.h"



@interface ViewController ()



@end



@implementation ViewController



- (void)viewDidLoad {

    [super viewDidLoad];

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

    NSArray *titles =@[@"alert", @"action"];

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

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];

        btn.frame = CGRectMake(100, 200+i*100, self.view.frame.size.width-200,50);

        

        [btn setTitle:titles[i] forState:UIControlStateNormal];

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

        btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];

        btn.tag= 100+i;

        [self.view addSubview:btn];

    }

}



- (void)btnClicked:(UIButton *)btn

{

    if (btn.tag==100) {

        //alert

        UIAlertView  *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"余额不足" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"充值", nil];

        [alert show];

    }

    else if (btn.tag == 101)

    {

        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"新浪微博" otherButtonTitles:@"QQ",@"微信",@"陌陌", nil];

        [sheet showInView:self.view];

    }

}





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

{

    NSLog(@"index = %li", buttonIndex);

}



- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    NSLog(@"index = %li", buttonIndex);

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end

 

你可能感兴趣的:(uialertview)