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

 

时间: 2024-08-23 06:02:47

UIKit 框架之UIActionSheet的相关文章

iOS UIKit 框架 346 篇文档分类整理 - 预告

iOS UIKit 框架 346 篇文档分类整理 - 预告 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 当前正在进行的是 "iOS Foundation 框架 224 篇相关文档分

UIKit 框架之UIView二

下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by cyw on 15-5-17. // Copyright (c) 2015年 cyw. All rights reserved. // #import "MyView.h" @implementation MyView - (id)initWithFrame:(CGRect)frame {

UIKit 框架之Bar、Controller

UIKit框架中有各种Bar,UITabBar.UINavigationBar.UIToolbar.Bar对应的就有一些Item,tabBarItem.navigationItem.toolbarItems,再加上UIViewController.UINavigationController.UITabBarController很容易搞糊涂.我看了好久,没看明白.动手敲了下才有一点感觉. 一.联系 一个UINavigationController对应着一个UINavigationBar.UITo

UIKit 框架之UIAlertController

IOS8之后增加了UIAlertController类,它可以表示UIAlertView和UIActionSheet.它继承自UIViewController. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window.backgroundColor=[UIColor whiteColor]; [self.wi

UIKit框架类层次图

学习UIKit应该首选了解UIKit类的层次图,从根类一层一层的拨.

UIKit 框架之UICollectionViewController

1.自定义单元格 #import <UIKit/UIKit.h> @interface myCollectionViewCell : UICollectionViewCell @property(nonatomic,strong) UIImageView *myImageView; @property(nonatomic,strong) UILabel *nameLabel; @end #import "myCollectionViewCell.h" @implementa

UIKit 框架之UIView一

- (id)initWithFrame:(CGRect)aRect //通过一个矩形对象初始化 Configuring a View's Visual Appearance //配置视觉展示 @property(nonatomic, copy) UIColor *backgroundColor //设置背景色 @property(nonatomic, getter=isHidden) BOOL hidden //隐藏view,默认为NO @property(nonatomic) CGFloat

UIKit 框架之UICollectionView

1.自定义UICollectionViewCell 在myCollectionViewCell.h中声明两个属性 // // myCollectionViewCell.h // UICollectionView // // Created by City--Online on 15/5/25. // Copyright (c) 2015年 XQB. All rights reserved. // #import <UIKit/UIKit.h> @interface myCollectionVi

UIKit框架之NSObject

首先学习NSObject  // // ViewController.m // localization // // Created by City--Online on 15/5/15. // Copyright (c) 2015年 XQB. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (voi