这是一个用于 iOS 的临时和不显眼的透明警报视图。它的样子如下:[iPad] / [iPhone]
OLGhostAlertView 允许您在屏幕底部呈现一个带有标题和可选信息的透明警报视图。可以使用它来通知用户有关临时问题,这些问题不需要立即采取任何行动,也不影响应用流程。
OLGhostAlertView 可以像 UIAlertView 一样具有标题和可选信息。它会在可配置的时间间隔后自动淡出,默认情况下,可以通过轻触来关闭。它可以自动根据部署的设备、用户界面方向和传递给它的字符串长度调整其大小。
OLGhostAlertView 需要在您的项目中包含 QuartzCore.framework。一旦您执行了此操作,请将 OLGhostAlertView 文件添加到您的项目中,并在您将要使用它的文件中导入头文件,如下所示:
#import "OLGhostAlertView.h"
然后,这是如何呈现一个 OLGhostAlertView:
OLGhostAlertView *ghastly = [[OLGhostAlertView alloc] initWithTitle:@"I am the walrus." message: @"Sitting on a cornflake, waiting for the van to come."];
[ghastly show];
就像 UIAlertView 一样,视图的关闭由视图本身处理,因此无需调用任何其他东西。如果您想手动关闭它,只需在实例上调用 hide
。
OLGhostAlertView 必须在根视图控制器上调用 viewDidAppear:
之后或同时显示。如果您在之前调用 show
,则实例可能不可见。
从版本 1.7 开始,您可以通过调用 showInView:
代替 show
只在您选择的视图中显示 OLGhostAlertView。
公开所有可用的选项。
- (id)initWithTitle:(NSString *)title message:(NSString *)message timeout:(NSTimeInterval)timeout dismissible:(BOOL)dismissible;
标题
显示在视图标题标签中的字符串。
信息
提供比标题更多详细信息的描述性文本。可以是 nil
。
超时
在警报自动关闭之前的时间间隔。
可关闭
警报是否可以通过触摸来关闭。
等效于initWithTitle:message:timeout:dismissible:
,但默认值为timeout
(6
秒)和dismissible
(YES
)。
- (id)initWithTitle:(NSString *)title message:(NSString *)message;
等效于initWithTitle:message:timeout:dismissible:
,但默认值为message
(nil
),timeout
(4
秒)和dismissible
(YES
)。
- (id)initWithTitle:(NSString *)title;
视图的垂直位置。
@property (nonatomic) OLGhostAlertViewPosition position;
此属性控制视图在Y轴上的起始位置。
默认值为OLGhostAlertViewPositionBottom
。
视图的视觉效果。
@property (nonatomic) OLGhostAlertViewStyle style;
视图可以是浅色文字在深色背景上(OLGhostAlertViewStyleDark
)或深色文字在上浅色背景上(OLGhostAlertViewStyleLight
)。
默认值为OLGhostAlertViewStyleDefault
,这对应于OLGhostAlertViewStyleLight
。
在实例被关闭后执行的代码块。
@property (nonatomic, copy) void (^completionBlock)(void);
出现在警告标题中的字符串。
@property (nonatomic) NSString *title;
初始化后设置此属性会重新计算视图的度量。
提供比标题更多详细信息的描述性文本。
@property (nonatomic) NSString *message;
初始化后设置此属性会重新计算视图的度量。
显示标题的标签。
@property (nonatomic, strong) UILabel *titleLabel;
显示标题的标签。
@property (nonatomic, strong) UILabel *messageLabel;
防止警告在它上面绘制的边距。
@property (nonatomic) CGFloat topContentMargin;
防止警告在它下面绘制的边距。
@property (nonatomic) CGFloat bottomContentMargin;
在警报自动关闭之前的时间间隔。
@property (nonatomic) NSTimeInterval timeout;
警报是否可以通过触摸来关闭。
@property (nonatomic) BOOL dismissible;
一个布尔值,表示视图目前是否显示在屏幕上。
@property (nonatomic, readonly, getter=isVisible) BOOL visible;
以下是OLGhostAlertView目前的一些限制
您可以在问题页面找到最新列表,其中包含完整的描述和讨论。
我们构建OLGhostAlertView是因为我们需要一个项目中的它。它肯定不是完美的(毕竟是由一个设计师构建的),并且它并不能做到它所能做到的一切。如果您在任何方面改进了它,请给我们发送一个pull request。祝你玩的愉快!