NYAlertViewController 1.3.0

NYAlertViewController 1.3.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最近发布2015年9月

Nealon Young 维护。




NYAlertViewController 是 UIAlertController/UIAlertView 的替代品,支持内容视图和 UI 定制。

Example

功能

  • 包括用于向警报视图添加自定义视图的内容视图属性
  • 类似于 UIAlertController/UIAlertAction 的基于 Block 的 API
  • 支持所有屏幕方向和 iPad 屏幕大小
  • 通过与 UIAlertController 相同的简单 API 可轻松添加文本字段
  • 选择淡入(类似于 UIAlertController)或滑入/滑出过渡动画

安装

手动

通过将 NYAlertViewController 目录拖放到您的 Xcode 项目中,手动将文件添加到您的项目中。

使用示例

NYAlertViewControllerDemo 目录中包含一个 Objective-C 示例项目,演示了自定义选项。

Objective-C

// Import the class and create an NYAlertViewController instance
#import "NYAlertViewController.h"

// ...

NYAlertViewController *alertViewController = [[NYAlertViewController alloc] initWithNibName:nil bundle:nil];

// Set a title and message
alertViewController.title = NSLocalizedString(@"Custom UI", nil);
alertViewController.message = NSLocalizedString(@"Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec id elit non mi porta gravida at eget metus.", nil);

// Customize appearance as desired
alertViewController.buttonCornerRadius = 20.0f;
alertViewController.view.tintColor = self.view.tintColor;

alertViewController.titleFont = [UIFont fontWithName:@"AvenirNext-Bold" size:19.0f];
alertViewController.messageFont = [UIFont fontWithName:@"AvenirNext-Medium" size:16.0f];
alertViewController.buttonTitleFont = [UIFont fontWithName:@"AvenirNext-Regular" size:alertViewController.buttonTitleFont.pointSize];
alertViewController.cancelButtonTitleFont = [UIFont fontWithName:@"AvenirNext-Medium" size:alertViewController.cancelButtonTitleFont.pointSize];

alertViewController.swipeDismissalGestureEnabled = YES:
alertViewController.backgroundTapDismissalGestureEnabled = YES:

// Add alert actions
[alertViewController addAction:[NYAlertAction actionWithTitle:NSLocalizedString(@"Done", nil)
                                                        style:UIAlertActionStyleCancel
                                                      handler:^(NYAlertAction *action) {
                                                          [self dismissViewControllerAnimated:YES completion:nil];
                                                      }]];

// Present the alert view controller
[self presentViewController:alertViewController animated:YES];

Swift

import NYAlertViewController

// ...

let alertViewController = NYAlertViewController()

// Set a title and message
alertViewController.title = "Custom UI"
alertViewController.message = "Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec id elit non mi porta gravida at eget metus."

// Customize appearance as desired
alertViewController.buttonCornerRadius = 20.0
alertViewController.view.tintColor = self.view.tintColor

alertViewController.titleFont = UIFont(name: "AvenirNext-Bold", size: 19.0)
alertViewController.messageFont = UIFont(name: "AvenirNext-Medium", size: 16.0)
alertViewController.cancelButtonTitleFont = UIFont(name: "AvenirNext-Medium", size: 16.0)
alertViewController.cancelButtonTitleFont = UIFont(name: "AvenirNext-Medium", size: 16.0)

alertViewController.swipeDismissalGestureEnabled = true
alertViewController.backgroundTapDismissalGestureEnabled = true

// Add alert actions
let cancelAction = NYAlertAction(
    title: "Done",
    style: .Cancel,
    handler: { (action: NYAlertAction!) -> Void in
        self.dismissViewControllerAnimated(true, completion: nil)
    }
)
alertViewController.addAction(cancelAction)

// Present the alert view controller
self.presentViewController(alertViewController, animated: true, completion: nil)

待办事项

  • 添加不同的过渡选项(淡入、从顶部滑动等)

许可证

本项目发布在 MIT 许可证下。