效果圖(ps:沒有效果圖,怎么看的下去)
FQ_AlertTipView.gif
前言:只是剛好看到別人App自定義的彈框挺不錯.自己花點時間封裝了一下.支持橫豎屏切換!
介紹:
-------------------提示框樣式----------------------
typedef NS_ENUM (NSInteger, FQ_AlertType)
{
FQ_AlertTypeActionAlert = 0 , //中間
FQ_AlertTypeActionTop , //頂部
FQ_AlertTypeActionSheet, //底部
};
-------------------Action樣式----------------------
typedef NS_ENUM (NSInteger, FQ_AlertActionType)
{
FQ_AlertActionStyleDefault = 0, //默認樣式
FQ_AlertActionStyleConfirm, //確定樣式
FQ_AlertActionStyleDestructive, //慎重樣式
FQ_AlertActionStyleCancel //取消樣式
};
主要三個類:
1.配置類:FQ_AlertConfiguration
.如果需要豐富.可以添加什么文字邊距等.我做了默認處理
//FQ_AlertActionStyleDefault = 0, //默認樣式
@property (strong, nonatomic) UIColor *defaultTextColor;
@property (strong, nonatomic) UIColor *defaultBackgroundColor;
@property (strong, nonatomic) UIFont *defaultTextFont;`
......
@property (assign, nonatomic) CGFloat cornerRadius;
// 默認的配置項.類屬性.(蘋果兼容swift添加的屬性)
@property (class, nonatomic) FQ_AlertConfiguration *defaultConfiguration;
2.響應控件配置類:FQ_AlertAction
.其實就是按鈕
` //初始化.
+ (instancetype)actionWithTitle:( NSString *)title type:(FQ_AlertActionType)actionType handler:(void (^)(FQ_AlertAction *action))handler;`
3.展示類:FQ_AlertView
.
/**
快捷展示多種樣式
@param title 標題
@param message 內容信息
@param alertType 展示樣式
@param confirmActionStr 確定Action樣式文本
@param otherActionStrArr 其他Action樣式文本數組
@param destructiveActionStr 刪除Action樣式文本
@param configuration 配置文件
@param actionBlock 點擊Action回調
@return AlertView
*/
+ (instancetype)showAlertViewWithTitle:(NSString *)title
message:(NSString *)message
alertType:(FQ_AlertType)alertType
confirmActionStr:(NSString *)confirmActionStr
otherActionStrArr:(NSArray *)otherActionStrArr
destructiveActionStr:(NSString *)destructiveActionStr
cancelActionStr:(NSString *)cancelActionStr
configuration:(FQ_AlertConfiguration*)configuration
actionBlock:(void(^)(FQ_AlertAction * action))actionBlock;
其他類
1.管理類:FQ_AlertViewManager
.保證當前界面只顯示一個FQAlertView控件.一般情況下沒有同時出現的情況.
2.工具類:FQ_AlertWindowVc
.彈框ContentView使用UIWindow.在處理橫豎屏切換時用到.
使用:
1.快捷創建方式:一句代碼搞定
[FQ_AlertView showAlertViewWithTitle:@"可以的" message:@"取消關注以后!您將再也收不到該用戶的所有動態?" alertType:FQ_AlertTypeActionSheet confirmActionStr:@"確定" otherActionStrArr:nil destructiveActionStr:nil cancelActionStr:@"取消" configuration:nil actionBlock:^(FQ_AlertAction *action) {
NSLog(@"action= %@",action.title); //根據字符串比較找到對應的Action事件做處理
}];
2.自定義方式創建:(借鑒蘋果創建方式)
FQ_AlertView * alertView = [FQ_AlertView showAlertViewWithTitle:@"確定?" message:@"隨便打得XXXXXXXXXXXXXXXXXXXX,可以嗎?" alertType:FQ_AlertTypeActionSheet configuration:nil];
FQ_AlertAction * test = [FQ_AlertAction actionWithTitle:@"拍攝" type:FQ_AlertActionStyleConfirm handler:^(FQ_AlertAction *action) {
NSLog(@"點擊拍攝");
}];
FQ_AlertAction * test1 = [FQ_AlertAction actionWithTitle:@"從手機相冊選擇" type:FQ_AlertActionStyleConfirm handler:^(FQ_AlertAction *action) {
NSLog(@"點擊從手機相冊選擇");
}];
FQ_AlertAction * test2 = [FQ_AlertAction actionWithTitle:@"取消" type:FQ_AlertActionStyleCancel handler:^(FQ_AlertAction *action) {
NSLog(@"點擊取消");
}];
[alertView addAction:test];
[alertView addAction:test1];
[alertView addAction:test2];
[alertView showAlertView];
END:暫未上傳至github賬號!需要請留言!