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

UIKit 框架之UIActionSheet

时间:2015-05-18 18:10:30      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/cuiyw/p/4512237.html

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