您的位置:首页 > 产品设计 > UI/UE

OneDayOneClass----UIActionSheet

2015-04-23 10:11 239 查看
// 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:@"取消"];
    }
    
}


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

哦了~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: