zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    Linux Shell 编程
    Linux下压缩与解压
    rsync实现文件备份同步
    linux中ulimit作用
    3dmax卡通渲染插件pencil+渲染线框
    世嘉开发部部长:这3点能提升游戏留存率
    消息中间件 分布式
    高并发高性能
    你的系统如何支撑高并发
    分布式系统的阿喀琉斯之踵:数据一致性
  • 原文地址:https://www.cnblogs.com/0515offer/p/4638803.html
Copyright © 2011-2022 走看看