提示框(二维码)

//按钮生成二维码
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((self.view.frame.size.width-230)/2, 150, 230, 40)];
[btn setTitle:@“生成二维码” forState:UIControlStateNormal];
btn.backgroundColor = [UIColor redColor];
[btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
//二维码存放地方
imgV = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 230, 200, 200)];
[self.view addSubview:imgV];

-(void)btn{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@“提示” message:@“请输入个人信息” preferredStyle:UIAlertControllerStyleAlert];
//增加确定按钮;
[alertController addAction:[UIAlertAction actionWithTitle:@“确定” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//获取第1个输入框;
self->userNameTextField = alertController.textFields.firstObject;
NSLog(@"%@",self->userNameTextField);
//运用方法来生成二维码
self->img = [QRCodeGenerator qrImageForString:self->userNameTextField.text imageSize:self->imgV.bounds.size.width];
//添加给imgV
self->imgV.image = self->img;
}]];
//增加取消按钮;
[alertController addAction:[UIAlertAction actionWithTitle:@“取消” style:UIAlertActionStyleDefault handler:nil]];

//定义第一个输入框;
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
    textField.placeholder = @"请输入用户名";
}];
[self presentViewController:alertController animated:true completion:nil];

}

你可能感兴趣的:(二维码)