iOS中有两个弹出视图的控件,分别是UIActionSheet和UIAlterView.效果图如下:
主要代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton * button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(, , , );
button1.backgroundColor = [UIColor cyanColor];
[button1 addTarget:self action:@selector(onclick1:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1]; UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake( , , , );
button2.backgroundColor = [UIColor redColor];
[button2 addTarget:self action:@selector(onclick2:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2];
}
-(void)onclick1:(UIButton *)btn{
UIActionSheet * actionsheet = [[UIActionSheet alloc]initWithTitle:@"提示信息" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确认" otherButtonTitles:nil];
[actionsheet showInView:self.view];
}
-(void)onclick2:(UIButton *)btn{
UIAlertView * alterView = [[UIAlertView alloc]initWithTitle:@"警告" message:@"您的言论违法中华人民共和国法律,有可能查你水表" delegate:self cancelButtonTitle:@"继续发表" otherButtonTitles:nil];
[alterView show];
}