UIKit 框架之UIActionSheet

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值