SMAlertView
是一个简洁易用的iOS AlertView。
CocoaPods是一个Objective-C的依赖管理器,它自动化并简化了在项目中使用类似于SMAlertView
的第三方库的过程。首先,将以下行添加到您的Podfile
pod 'SMAlertView', '~> 1.0.1'
然后,将SMAlertView
安装到您的项目中
pod install
将AlertDemo/SMAlert
文件夹拖入您的项目中。
(请参阅SMAlertView
中的示例Xcode项目)
SMAlertView
以单例的形式创建(即不需要显式分配和初始化;直接调用[SMAlert method]
)。
您可以使用以下任一方法只显示内容:
+ (void)showContent:(NSString*)content;
+ (void)showContent:(NSString*)content confirmButton:(SMButton*)confirmButton;
+ (void)showContent:(NSString*)content confirmButton:(SMButton*)confirmButton cancleButton:(SMButton*)cancleButton;
如果您想要带有图像的AlertView
+ (void)showImage:(UIImage*)image content:(NSString*)content;
+ (void)showImage:(UIImage*)image content:(NSString*)content confirmButton:(SMButton*)confirmButton;
+ (void)showImage:(UIImage*)image content:(NSString*)content confirmButton:(SMButton*)confirmButton cancleButton:(SMButton*)cancleButton;
此外,您还可以显示带有自定义视图的AlertView
+ (void)showCustomView:(UIView*)view;
+ (void)showCustomView:(UIView*)view confirmButton:(SMButton*)confirmButton;
+ (void)showCustomView:(UIView*)view confirmButton:(SMButton*)confirmButton cancleButton:(SMButton*)cancleButton;
可以使用以下方法关闭AlertView:
+(void)hide; //隐藏当前AlertView
+(void)hideAll; //隐藏当前AlertView并清空待显示队列
如果您想在AlertView隐藏完成后执行某些动作
+(void)hideCompletion:(void (^)(void))completion;
SMAlertView
可以通过以下方法进行定制:
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15
+ (void)setAlertBackgroundColor:(UIColor*)color; // default is clear clolor
+ (void)setConfirmBtBackgroundColor:(UIColor*)color; // default is white clolor
+ (void)setCancleBtBackgroundColor:(UIColor*)color; // default is white clolor
+ (void)setConfirmBtTitleColor:(UIColor*)color; // default is red clolor
+ (void)setCancleBtTitleColor:(UIColor*)color; // default is blue clolor
+ (void)setContentTextColor:(UIColor*)color; // default is black clolor
+ (void)setContentFont:(UIFont*)font; // default is 15
+ (void)setBtTitleFont:(UIFont*)font; // default is 15
+ (void)setContentLineSpace:(CGFloat)lineSpace; // default is 4
+ (void)setTouchToHide:(BOOL)touchToHide; // default is NO
+ (void)setContentTextAlignment:(NSTextAlignment)textAlignment; // default is left
SMAlert
遵守MIT许可证的条款和条件