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

UIActionSheet

时间:2015-11-04 09:19:28      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

#import "RootViewController.h"

 

@interface RootViewController ()<UIActionSheetDelegate>

 

@end

 

@implementation RootViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];

    button.layer.borderWidth = 2;

    [button setTitle:@"showSheet" forState:(UIControlStateNormal)];

    [button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];

    [self.view addSubview:button];

    [button addTarget:self action:@selector(show) forControlEvents:(UIControlEventTouchUpInside)];

    

}

 

- (void)show {

    //UIActionSheet , 继承于UIView .

    //创建方法

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"提示" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"destructiveButton" otherButtonTitles:@"1", @"2", @"3", nil];

    actionSheet.title = @"名字";//这里的 title 就是 创建方法里面的initWithTitle

    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;//设置样式

    //按钮的index destructiveButton , 1 ,2, 3, cancel , 分别是0 1 2 3 4

    /*//四种样式

    UIActionSheetStyleDefault

    UIActionSheetStyleAutomatic

    UIActionSheetStyleBlackOpaque

    UIActionSheetStyleBlackTranslucent

     */

    [actionSheet showInView:self.view];

     

    [actionSheet release];

 

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{//代理里面的方法, 点击了哪个按钮

    if (0 == buttonIndex) {

        NSLog(@"0");

    } else if (1 == buttonIndex) {

        NSLog(@"1");

    } else if (2 == buttonIndex) {

        NSLog(@"2");

    } else if (3 == buttonIndex) {

         NSLog(@"3");

     } else {

        NSLog(@"4");

    }

}

 

 

 

@end

 

UIActionSheet

标签:

原文地址:http://www.cnblogs.com/hsxblog/p/4934988.html

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