前言:
从 我们熟悉的UIAlertView和UIActionsheet 在IOS 8 之后,被苹果融合为UIAlertController 。以往的写法一个样式得写一套灵活性较差。ios8以后,UIAlertcontroller 的使用改善了以往的两种提示,增加了灵活性。但是UIalertController 也有自己的弊端。弊端:它样式单一、该类提供的API也没有可以更改的Func 。优点:使用简单方便、苹果的简约风格。但是,这么好的提示,也满足不了我们开发APP的设计工程师的眼睛。为了更好的使用提示,我自己就做了一个,功能简单。有不足的地方还请海涵。
第一:效果
本框架一共有两个样式(Alert and ActionSheet)。如下:
第二:静态库的介绍
介绍:KAlerVController.h
//
// KAlertVController.h
// KUIAlertController
//
// Created by 周双建 on 16/5/16.
// Copyright © 2016年周双建. All rights reserved.
//
#import <UIKit/UIKit.h>
// base type
typedef NS_ENUM(NSInteger,KAlertType){
KAlertController= 0,
KAlertControllerSheet,
};
// func back
typedef void( ^ Selblock)(UIButton* Action);
@interface KAlertVController : UIView
// 设计三个量
// heart
@property(nonatomic)UILabel * KAlertTitle;
// body
@property(nonatomic)UILabel * KAlertMesage;
// back——view
@property(nonatomic)UIView * KAlertBackView;
// readonly object type
@property(nonatomic)KAlertType Alerttype;
// make object func
+(KAlertVController*)addtitle:(NSString*)title message:(NSString*)message type:(KAlertType)type;
// you can set textcolor and font of title
-(void)settitlecolor:(UIColor*)color;
-(void)settitlefont:(UIFont*)font;
// you can set textcolor and font of title
-(void)setmessagecolor:(UIColor*)color;
-(void)setmessagefont:(UIFont*)font;
// Add event
-(void)addAction:(NSArray*)actionobject action:(Selblock)action;
/***********************************************************************/
// other type
+(KAlertVController*)addAlerSheettitle:(NSString*)title actionsheet:(NSArray*)actionsheet action:(Selblock)action;
@end
// you can setting your alert type in here
// Alert type used
KAlertVController * AK = [KAlertVController addtitle:@"Success-Bar" message:@"月落乌啼霜满天,江枫渔火对愁眠。姑苏城外寒山寺,夜半钟声到客船" type:KAlertController];
AK.KAlertTitle.textColor = [UIColor redColor];
// set color of alert message
[AK setmessagecolor:[UIColor magentaColor]];
// set font of alert title
[AK settitlefont:[UIFont fontWithName:@"Zapfino" size:20]];
// set font of alert message
[AK setmessagefont:[UIFont systemFontOfSize:12]];
[AK addAction:@[@"离去",@"停泊"] action:^(UIButton *Action) {
// change backView color
Action.backgroundColor = [UIColor redColor];
// change font of action title
[Action setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// action event
[Action addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];
}];
-(void)Click:(UIButton*)Mybtn{
// The corresponding event
if (Mybtn.tag==0) {
NSLog(@"欢迎下次再来");
// cancle ( one type)
for (UIView * TempViewin [UIApplicationsharedApplication].keyWindow.subviews) {
if ([TempView isMemberOfClass:[KAlertVController class]]) {
[TempView removeFromSuperview];
}
}
}else{
// other action event
NSLog(@"亲这里不是温暖的港湾");
}
}
KAlertVController * AKSheet = [KAlertVControlleraddAlerSheettitle:@"请选择选择"actionsheet:@[@"相机",@"相册",@"取消"]action:^(UIButton *Action) {
[Action addTarget:selfaction:@selector(ActionSheetClick:)forControlEvents:UIControlEventTouchUpInside];
}];
// AlertSheet actionEvent
-(void)ActionSheetClick:(UIButton*)AsBtn{
if (AsBtn.tag==0) {
NSLog(@"您选择了相机");
}else if (AsBtn.tag==1){
NSLog(@"您选择了相册");
}else{
NSLog(@"您取消选择");
for (UIView * TempViewin [UIApplicationsharedApplication].keyWindow.subviews) {
if ([TempView isMemberOfClass:[KAlertVController class]]) {
[TempView removeFromSuperview];
}
}
}
}