UIAlertView和UIActionSheet相似,区别很小, 很容易理解。

//
//  ViewController.m
//  UIActionSheet
//
//  Created by City--Online on 15/5/18.
//  Copyright (c) 2015年 XQB. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIActionSheetDelegate>
@property(nonatomic,strong) UIActionSheet *actionSheet;
@property(nonatomic,strong) UIActionSheet *actionSheet1;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //设置Frame无效
    _actionSheet=[[UIActionSheet alloc]initWithFrame:CGRectMake(20, 20, 200, 100)];
    [_actionSheet addButtonWithTitle:@"相册"];
    [_actionSheet addButtonWithTitle:@"相机"];
    [_actionSheet addButtonWithTitle:@"取消"];
    _actionSheet.cancelButtonIndex=2;
    _actionSheet.destructiveButtonIndex=1;
    _actionSheet.title=@"提示";

    _actionSheet.delegate=self;
//    typedef NS_ENUM(NSInteger, UIActionSheetStyle) {
//        UIActionSheetStyleAutomatic        = -1,       // take appearance from toolbar style otherwise uses 'default'
//        UIActionSheetStyleDefault          = UIBarStyleDefault,
//        UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
//        UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,
//    };
    _actionSheet.actionSheetStyle=UIActionSheetStyleBlackOpaque;
    _actionSheet.tag=10001;

    NSLog(@"firstOtherButtonIndex=%ld",_actionSheet.firstOtherButtonIndex);
    for (int i=0; i<_actionSheet.numberOfButtons; i++) {
        NSLog(@"i=%d %@",i,[_actionSheet buttonTitleAtIndex:i]);
    }
    [_actionSheet showInView:self.view];

    _actionSheet1 =[[UIActionSheet alloc]initWithTitle:@"提示" delegate:self cancelButtonTitle:@"NO" destructiveButtonTitle:@"DestructiveButton" otherButtonTitles:@"YES", nil];
    _actionSheet1.tag=10002;
    for (int i=0; i<_actionSheet1.numberOfButtons; i++) {
        NSLog(@"i=%d %@",i,[_actionSheet1 buttonTitleAtIndex:i]);
    }
    [_actionSheet1 showInView:self.view];

}
//UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet.tag==10001) {
        NSString *title=[_actionSheet buttonTitleAtIndex:buttonIndex];
        NSLog(@"我点击了: %@",title);
    }
    else
    {
        if (buttonIndex==2) {
            [_actionSheet dismissWithClickedButtonIndex:2 animated:YES];
        }
    }
}

//以下这些和UIAlertView的相似
- (void)actionSheetCancel:(UIActionSheet *)actionSheet
{
    NSLog(@"actionSheetCancel");
}

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
    NSLog(@"willPresentActionSheet");
}
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
{
    NSLog(@"didPresentActionSheet");
}

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"willDismissWithButtonIndex");
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"didDismissWithButtonIndex");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

UIKit 框架之UIActionSheet的更多相关文章

  1. UIKit框架使用总结--看看你掌握了多少

    一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...

  2. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  3. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  4. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  5. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  6. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  7. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  8. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

  9. UIKit 框架之UIView二

    下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...

随机推荐

  1. whu暑期集训#1

    题号:SGU123----SGU131 Problem A: 题意:求斐波那契的前N项和.. 做法:直接模拟,注意得用long long Problem B: 题意:给定一个封闭的多边形,求一个点在不 ...

  2. shell 命令 bc linux下的计算器

    bc命令 在linux环境下的计算器.

  3. [mobile]监听手机mobile上面软键盘的回车[enter]事件

    $(document).keypress(function(e) { if(e.which == 13) { if(!$(".qaSearchInput").val()) { Hn ...

  4. Matlab中函数句柄@的作用及介绍

    问:f=@(x)acos(x)表示什么意思?其中@代表什么?答:表示f为函数句柄,@是定义句柄的运算符.f=@(x)acos(x) 相当于建立了一个函数文件:% f.mfunction  y=f(x) ...

  5. Git项目下载部分文件或文件夹

    我们常常要在Github下载一些源码.示例等,但有时候项目库会比较大,而我关心的只是其中很少的一部分内容,由于众所周知的原因,我们下载git库是比较慢的,过大的项目经常会下载失败,所以只下载部分内容就 ...

  6. JVM活学活用——类加载机制

    类的实例化过程 有父类的情况 1. 加载父类静态    1.1 为静态属性分配存储空间并赋初始值     1.2 执行静态初始化块和静态初始化语句(从上至下) 2. 加载子类静态    2.1 为静态 ...

  7. CS231-Multi-calss SVM的求导

    接着上周的更,上周我们更到,在对图像的线性分类中,我们只用multi-class 的svm,然后我们得到以下的损失函数 这里每个数值代表为下: X 是一个 N by D 的矩阵,N 代表 traini ...

  8. Dubbo原理实现之与spring融合

    Spring中bean的定义可以通过编程,可以定义在properties文件,也可以定义在通过xml文件中,用的最多的是通过xml形式,由于xml格式具有很好的自说明便于编写及维护.对于xml的文档结 ...

  9. [Swift]lower_bound和upper_bound

    时间复杂度:一次查询O(log n),n为数组长度. [C++] lower_bound:返回大于等于val的第一个值 功能:查找非递减序列[first,last) 内第一个大于或等于某个元素的位置. ...

  10. Python-WSGI协议如何实现?

    简述浏览器通过WSGI 请求动态资源的过程? 发送 http 请求动态资源给 web 服务器 web 服务器收到请求后通过 WSGI 调用一个属性给应用程序框架 应用程序框架通过引用 WSGI 调用 ...