UIKit 框架之UIAlertController
2024-10-10 02:40:20
IOS8之后增加了UIAlertController类,它可以表示UIAlertView和UIActionSheet.它继承自UIViewController。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window.backgroundColor=[UIColor whiteColor]; [self.window makeKeyAndVisible]; ViewController *vc=[[ViewController alloc]init]; UINavigationController *nvc=[[UINavigationController alloc]initWithRootViewController:vc]; self.window.rootViewController=nvc; return YES; }
// // ViewController.m // AlertVC // // Created by City--Online on 15/5/25. // Copyright (c) 2015年 XQB. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; btn.frame=CGRectMake(100, 100, 50, 50); [btn setTitle:@"按钮" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; btn.layer.borderWidth=2.0; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } -(void)btnClick:(id)sender { // UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert]; // // [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text=@"name"; // textField.clearsOnBeginEditing=YES; // }]; // [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text=@"password"; // textField.clearsOnBeginEditing=YES; // }]; UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *actionOk=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"确定"); }]; UIAlertAction *actionCancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"取消"); }]; [alert addAction:actionOk]; [alert addAction:actionCancel]; [self presentViewController:alert animated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
最新文章
- CentOS6.3编译安装Memcached
- display:block 不起作用
- PHP基础之 继承(一)
- PHP、Java输出json格式数据
- PHP获取毫秒时间戳,利用microtime()函数
- POJ-1155 TELE (树形DP+分组背包)
- Raspberry Pi无线路由器篇
- Tree HDOJ--2682
- iOS---There was an internal API error 错误
- [Lua]基于cc.load('mvc') .ViewBase索引资源方案
- session与cookie的关系
- 乘法逆元...Orz
- 3dmax 3dmax计算机要求 3dmax下载
- Nginx 11阶段的顺序处理
- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project triage: Compilation failure [ERROR] No compiler is provided in this environment.
- CentOS7.3安装Go运行和开发环境
- javascript中的 return false和return true
- 细说tomcat之集群session共享方案
- Java作业(一)
- OOA/OOD&;UML部分