JTAlertView 是一种新的 精彩对话框/HUD/警报 类型的视图。它也设计用于满足在 定制 过程中的用户需求。使用图像、视差和弹出效果愉快地结合创建,JTAlertView 提升了您的用户体验。
有两种方法可以将 JTAlertView 库添加到您的项目中。作为常规库添加或通过 CocoaPods 安装。
pod 'JTAlertView'
您还可以使用以下方式快速测试示例项目
pod try JTAlertView
库需要针对 iOS 7.0 及以上版本的目标
可在横竖屏模式下运行
initWithTitle:andImage:
或类方法 alertWithTitle:andImage:
来初始化。overlayColor
来自定义 JTAlertView
。addButtonWithTitle:action:
show
和 hide
方法来处理显示。JTAlertView *alertView = [[JTAlertView alloc] initWithTitle:@"You are wonderful" andImage:image];
self.alertView.size = CGSizeMake(280, 230);
[self.alertView addButtonWithTitle:@"OK" style:JTAlertViewStyleDefault action:^(JTAlertView *alertView) {
[alertView hide];
}];
[self.alertView show];
您必须设置 size
属性,否则将使用默认值。popAnimation
在显示时可见,并且当您点击对话框时也会可见。上面给出的 overlayColor
和适当的 titleShadow
使得标题更易于阅读。创建 backgroundShadow
在警报视图下方创建适当的阴影。将应用 font
属性(它是 style
和 size
)到标题和按钮(仅 style
)。要自定义特定按钮,请使用按钮添加方法中的 font
参数(见下文)。
@property (nonatomic, assign) CGSize size;
@property (nonatomic, assign) bool popAnimation;
@property (nonatomic, assign) bool parallaxEffect;
@property (nonatomic, strong) UIColor *overlayColor;
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, strong) UIColor *titleColor;
@property (nonatomic, assign) bool titleShadow;
@property (nonatomic, assign) bool backgroundShadow;
您可以设置按钮的 title
、actionBlock
、style
(类似于 controlEvents
和 font
(如有必要)。
- (void)addButtonWithTitle:action:
- (void)addButtonWithTitle:style:action:
- (void)addButtonWithTitle:style:forControlEvents:action:
- (void)addButtonWithTitle:font:style:forControlEvents:action:
您可以使用带有 completion
块的 show
显示 JTAlertView,在特定的 superview
中,animated
并隐藏它,也可以使用 delay
。
- (void)show
- (void)showInSuperview:withCompletion:animated:
- (void)hide
- (void)hideWithCompletion:animated:
- (void)hideWithDelay:animated:
此库由Jakub Truhlar开源,网址为http://kubatruhlar.cz。
MIT许可(MIT)版权所有 © 2015 Jakub Truhlar