iOS8进一步将UI进行了统一。主要有需要知道的有以下几个:
01-UIAlertController
02-UIPopoverPresentationController
03-UIPresentationController
04-Sizeclass+Autolayout
05-App Extension
06-Core Image(iOS5.0开始,主要有滤镜,代表:美图秀秀)
07.......
------------------------华丽丽的分割线------------------------
UIActionSheet(操作表)用于迫使用户在两个或更多的选项之间进行选择的模式视图。操作表是从屏幕底部弹出,显示一系列按钮供用户选择,用户只有单击一个按钮后才能继续使用应用程序。(可以理解为桌面应用系统的右键菜单的功能)。注意:在ipad中,sheet并不是从底部滑出,而是出现在触发器的周围;并且没有“取消”按钮,及时代码中定义了,也不会显示
UIAlertView(警告框)默认是以蓝色圆形矩形形式显示在屏幕中央,警告框可显示一个或多个按钮,且为了让控制器类充当操作表的委托,控制器需要遵从UIActionSheetDelegate协议。主要应用场景:1.app不能继续运行 2.询问另外的解决方案 3.询问对操作的授权
创建项目:
// 危险操作:弹框提醒
// 1.UIAlertView
// 2.UIActionSheet
代码展示:
//
// ViewController.m
// uialertcontroller
//
#import "ViewController.h"
#import "NYViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"正在对敏感数据进行操作" preferredStyle:UIAlertControllerStyleActionSheet];
// 设置popover指向的item
alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;
// 添加按钮
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"点击了确定按钮");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}]];
[self presentViewController:alert animated:YES completion:nil];
}
// UIAlertControllerStyleActionSheet的使用注意
// 1.不能有文本框
// 2.在iPad中,必须使用popover的形式展示
// Text fields can only be added to an alert controller of style UIAlertControllerStyleAlert
// 只能在UIAlertControllerStyleAlert样式的view上添加文本框
- (void)alertController
{
// 危险操作:弹框提醒
// 1.UIAlertView
// 2.UIActionSheet
// iOS8开始:UIAlertController == UIAlertView + UIActionSheet
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"正在对敏感数据进行操作" preferredStyle:UIAlertControllerStyleAlert];
// 添加按钮
__weak typeof(alert) weakAlert = alert;//防止循环引用
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"点击了确定按钮--%@-%@", [weakAlert.textFields.firstObject text], [weakAlert.textFields.lastObject text]);
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}]];
// [alert addAction:[UIAlertAction actionWithTitle:@"其它" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// NSLog(@"点击了其它按钮");
// }]];
// 添加文本框
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.textColor = [UIColor redColor];
textField.text = @"123";
[textField addTarget:self action:@selector(usernameDidChange:) forControlEvents:UIControlEventEditingChanged];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(usernameDidChange:) name:UITextFieldTextDidChangeNotification object:textField];
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = YES;
textField.text = @"123";
}];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)usernameDidChange:(UITextField *)username
{
NSLog(@"%@", username.text);
}
- (void)actionSheet
{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"警告:正在对敏感数据进行操作" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定"
otherButtonTitles:@"关闭", nil];
[sheet showInView:self.view];
}
- (void)alertView
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"正在对敏感数据进行操作" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert show];
}
@end
运行结果:
1.alertView(UIAlertViewStyleDefault) 2.actionSheet总结:
网友评论