首页 > 代码库 > UI第十二节
UI第十二节
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(40, 100, 295, 30);
[btn setTitle:@"Show Alert View" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (void)btnClicked:(UIButton *)btn
{
// 实例化 UIAlertView
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"这是Title" message:@"这里是提示的信息" delegate:self cancelButtonTitle:@"取消按钮" otherButtonTitles:@"确认", nil];
// 显示UIAlertView
[alertView show];
}
// 用户点击UIAlertView上的按钮时会调用这个代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// 通过ButtonIndex来判断用户点击的是哪一个Button
NSLog(@"%ld, %@", buttonIndex, [alertView buttonTitleAtIndex:buttonIndex]);
}
UI第十二节