码迷,mamicode.com
首页 > 其他好文 > 详细

UI5_UIAlertView与UIActionSheet

时间:2015-07-11 16:30:56      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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

 

UI5_UIAlertView与UIActionSheet

标签:

原文地址:http://www.cnblogs.com/0515offer/p/4638803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!