OneDayOneClass----UIActionSheet

本文介绍了如何在 iOS 应用中使用 UIActionSheet 控件来显示操作菜单,并提供了具体的代码示例。包括如何创建 UIActionSheet 实例、设置样式、添加按钮以及处理用户的点击事件。

  // Created By 郭仔   2015年04月23日10:07:44

 // -========================

有一段时间没更新这个系列了!

// ==========================

首先通过button事件触发UIActionSheet:

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"标题" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"第一项",@"第二项", nil];
    
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    // 添加title
    [actionSheet addButtonWithTitle:@"添加的"];
    actionSheet.backgroundColor = [UIColor orangeColor];
    //actionSheet.tintColor = [UIColor redColor];
    
    NSLog(@"%@",[actionSheet buttonTitleAtIndex:0]);

    [actionSheet showInView:self.window];
    [actionSheet release];
然后封装showAlert方法,点击时,触发该方法:

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Action Sheet选择项"
                          message:msg
                          delegate:self
                          cancelButtonTitle:@"确定"
                          otherButtonTitles: nil];
    [alert show];
设置UIActionSheet的代理(协议:UIActionSheetDelegate)

实现协议中方法:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        [self showAlert:@"确定"];
    }else if (buttonIndex == 1) {
        [self showAlert:@"第一项"];
    }else if(buttonIndex == 2) {
        [self showAlert:@"第二项"];
    }else if(buttonIndex == 3) {
        [self showAlert:@"取消"];
    }
    
}

=============

哦了~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值