ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//初始化图片视图
UIImageView *imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
//设置与用户交互
imageView.userInteractionEnabled = YES;
[self.view addSubview:imageView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(300, 450, 100, 60);
btn.center = CGPointMake(imageView.frame.size.width/2, 500);
[btn setTitle:@"弹出提示" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor whiteColor];
btn.layer.cornerRadius = 20;
btn.layer.masksToBounds = YES;
btn.layer.borderWidth = 1;
btn.layer.borderColor = [UIColor blackColor].CGColor;
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];
}
-(void)click{
UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"注册" otherButtonTitles: nil];
[sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"注册新用户" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
UITextField *username = [alertView textFieldAtIndex:0];
UITextField *password = [alertView textFieldAtIndex:1];
NSLog(@"%@-\n--%@",username.text,password.text);
[[[UIAlertView alloc]initWithTitle:@"" message:[NSString stringWithFormat:@"用户名为:%@\n密码为:%@",username.text,password.text] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil] show];
}