// 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:@"取消"];
}
}
=============
哦了~