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. SQLSqlserver中如何将一列数据,不重复的拼接成一个字符串

    把一列数据拼接成一个字符串比较简单: declare @test varchar(500) set @test=''; select @test=@test+name+',' from person ...

  2. JS学习笔记8_错误处理

    1.错误处理语法:(js没有异常exception一说,都是错误error) try{ //throw new Error(msg); //throw '错误'; //throw false; //t ...

  3. 在线安装WordPress更新 失败的解决办法

    1.  登录ftp登录不上 , 总是登录失败 在服务器上新建了一个vsftpd服务器,并设置了相应的虚拟用户,修改chroot到网站目录 相关连接:https://blog.csdn.net/zhan ...

  4. 通过EntityFramework操作sqlite(DbFirst)

    记录一下通过 EntityFramework6 来操作sqlite过程 环境: visual studio 2017 .net 4.5 Console Application(项目类型) sqlite ...

  5. git add .添加不成功

    情景: 我首先在一个有许多文件的文件夹中  git init  创建一个git管理仓库 之后 git add . 之后 git commit -m "提交" 发现提交不成功,文件没 ...

  6. django 之 发送邮箱

    发送邮箱的话首先在settings文件里写下边的这些设置: #邮件服务配置文件 SSL认证,验证 EMAIL_USE_SSL = True #邮箱服务 EMAIL_HOST = 'smtp.qq.co ...

  7. UI的设计,适配器,以及RecyclerView无法加载的解决办法

    这本书里讲到的界面设计都是用最基本的方式实现的,即编写xml文件 所有的控件都具有宽度和高度属性,即android:layout_width和android:layout_height,这两个属性对应 ...

  8. POJ 2707

    #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int ...

  9. C#递归方法遍历目录及子目录

    众所周知,获得某一目录下第一级的所有文件和文件夹列表,很容易办到:DirectoryInfo di=new DirectoryInfo(strBaseDir);//strBaseDir是起始目录,绝对 ...

  10. 09-01 Java final,多态,抽象类,接口

    final /* final可以修饰类,方法,变量 特点: final可以修饰类,该类不能被继承. final可以修饰方法,该方法不能被重写.(覆盖,复写) final可以修饰变量,该变量不能被重新赋 ...