天天看点

OneDayOneClass----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:@"取消"];
    }
    
}
           

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

哦了~