iOS9 升级后UIAlertController的简单使用

来源:互联网 发布:怎么开发java手机游戏 编辑:程序博客网 时间:2024/05/19 23:27
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    button.frame = CGRectMake(100, 100,100, 100);    [button addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];    button.backgroundColor = [UIColor blueColor];    [self.view addSubview:button];    }- (void)actionButton:(UIButton *)button {    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"开心" preferredStyle:UIAlertControllerStyleAlert];    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {        NSLog(@"111");    }];    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {        NSLog(@"222");    }];        [alertController addAction:okAction];    [alertController addAction:cancelAction];        [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {        textField.placeholder = @"用户名";        textField.secureTextEntry = YES;    }];    [self presentViewController:alertController animated:YES completion:nil];}@end<img src="http://img.blog.csdn.net/20160207091452331?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
运行效果如下:
0 0
原创粉丝点击