iOS 封装全局提示框

很多时候产品都有需求, 要提示框, 提示框提示框!!!  系统的太难看了, (ーー゛)我勒个.  让UI给个标准吧我做o(╯□╰)o

其实很简单 可以根据要求让它以各种动画形式出现消失.

command+ n 创建UIView 的类 ,命名为  AWPopView

AWPopView.h文件

//取消按钮点击事件

typedef void(^cancelBlock)();

//确定按钮点击事件

typedef void(^sureBlock)();

@interface AWPopView : UIView

@property(nonatomic,copy)cancelBlock cancel_block;

@property(nonatomic,copy)sureBlock sure_block;

/**

*  简书号:iOS_啊伟  http://www.cnblogs.com/chenwei-dcav/

*

*  @param title       标题

*  @param content     内容

*  @param sure        确定按钮内容

*  @param sureBlock   确定按钮点击事件

*

*  @return SZKAlterView

*/

+(instancetype)alterViewWithTitle:(NSString *)title

content:(NSString *)content

sure:(NSString *)sure

sureBtClcik:(sureBlock)sureBlock;

AWPopView.m文件

#define WIDTH  [UIScreen mainScreen].bounds.size.width

#define HEIGHT  [UIScreen mainScreen].bounds.size.height

@interface  AWPopView()

@property(nonatomic,retain)UIView *alterView;

@property(nonatomic,retain)UILabel *titleLb;

@property(nonatomic,retain)UILabel *contentLb;

@property(nonatomic,retain)UIButton *sureBt;

@property(nonatomic,copy)NSString *title;

@property(nonatomic,copy)NSString *content;

@property(nonatomic,copy)NSString *cancel;

@property(nonatomic,copy)NSString *sure;

@end

@implementation AWPopView

-(instancetype)initWithFrame:(CGRect)frame

{

self=[super initWithFrame:frame];

if (self) {

//标题

_titleLb=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 15)];

_titleLb.textColor=SetColor(111, 208, 199);

_titleLb.font = [UIFont systemFontOfSize:16];

_titleLb.adjustsFontForContentSizeCategory = YES;

[self addSubview:_titleLb];

_titleLb.sd_layout.leftSpaceToView(self, 22.5).topSpaceToView(self, 15).widthIs(70).heightIs(15);

//内容

_contentLb=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titleLb.frame) + 30, self.bounds.size.width, 15)];

_contentLb.font = [UIFont systemFontOfSize:15];

[self addSubview:_contentLb];

_contentLb.sd_layout.leftSpaceToView(self, 22.5).topSpaceToView(_titleLb, 30).widthIs(self.bounds.size.width).heightIs(15);

//确定按钮

_sureBt=[[UIButton alloc]initWithFrame:CGRectMake(self.bounds.size.width/2, CGRectGetMaxY(_contentLb.frame), 120, 40)];

_sureBt.centerX = self.centerX;

_sureBt.layer.cornerRadius = 5;

_sureBt.layer.masksToBounds = YES;

_sureBt.backgroundColor = SetColor(111, 208, 199);

[_sureBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

[_sureBt addTarget:self action:@selector(sureBtClick) forControlEvents:UIControlEventTouchUpInside];

[self addSubview:_sureBt];

_sureBt.sd_layout.leftSpaceToView(self, (self.bounds.size.width - 120)/2).bottomSpaceToView(self, 20).widthIs(120).heightIs(40);

}

return self;

}

#pragma mark----实现类方法

+(instancetype)alterViewWithTitle:(NSString *)title

content:(NSString *)content

sure:(NSString *)sure

sureBtClcik:(sureBlock)sureBlock;

{

AWPopView *alterView=[[AWPopView alloc]initWithFrame:CGRectMake(0, 0, 345, 200)];

alterView.backgroundColor=[UIColor whiteColor];

alterView.center=CGPointMake(WIDTH/2, HEIGHT/2 +20);

alterView.layer.cornerRadius=5;

alterView.layer.masksToBounds=YES;

alterView.title=title;

alterView.content=content;

alterView.sure=sure;

alterView.sure_block=sureBlock;

return alterView;

}

#pragma mark--给属性重新赋值

-(void)setTitle:(NSString *)title

{

_titleLb.text=title;

}

-(void)setContent:(NSString *)content

{

_contentLb.text=content;

}

-(void)setSure:(NSString *)sure

{

[_sureBt setTitle:sure forState:UIControlStateNormal];

}

#pragma mark----确定按钮点击事件

-(void)sureBtClick

{

[self removeFromSuperview];

self.sure_block();

}

类也写完了 , 激动人心的时刻到了, 让他再任何ViewController 出现消失

ViewController.m 文件

//添加淡黑色背景, 弹框出现其他地方不能点击

UIWindow * window = [[UIApplication sharedApplication]keyWindow];

UIView * BlackView = [[UIView alloc]init];

BlackView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];

[window addSubview:BlackView];

BlackView.sd_layout.leftSpaceToView(window, 0).topSpaceToView(window, 0).rightSpaceToView(window, 0).bottomSpaceToView(window, 0);//做好适配

AWPopView *lll=[AWPopView alterViewWithTitle:@"系统提示" content:@"需要重新登录" sure:@"确定" sureBtClcik:^{

BlackView.alpha = 0.0f;

LoginViewController * login = [[LoginViewController alloc]init];

[self.navigationController pushViewController:login animated:YES];

}];

[window addSubview:lll];

直接类方法创建, 就是这么sou eaey . 弹框里面的按钮标题可以去类里面随便加  , 如果觉得不够过瘾的iOS 妹子可以加QQ  751045314 ,阿伟不介意我们深入沟通哦,要demo留下QQ发邮箱

时间: 2025-01-15 18:16:28

iOS 封装全局提示框的相关文章

封装的提示框

-(void)createAlerViewWithTitle:(NSString *)title message:(NSString *)message{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; }

iOS:提示框(警告框)控件UIActionSheet的详解

提示框(警告框)控件2:UIActionSheet 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能.它与导航栏类似,它继承自UIView. 风格类型: typedef NS_ENUM(NSInteger, UIActionSheetStyle) { UIActionSheetStyleAutomatic        = -1,       //iOS系统自动默认的风格 UIActionSheetStyleDefault          = UIB

【iOS开发-56】案例BUG:按钮的enabled、控件的userInteractionEnabled以及两种提示框UIAlert和UIActionSheet

接上述案例找BUG:[iOS开发-51]案例学习:动画新写法.删除子视图.视图顺序.延迟方法.按钮多功能用法及icon图标和启动页设置 (1)BUG:答案满了就不能再点击option按钮,答案没满就能点. 在optionClick方法的if(full)中设置,即判断答案是否满了,如果满了,则: if (full) { //如果答案满了,不管是否正确,只要满了,下面的option按钮就不能被点击 for (UIButton *optionBtn in self.optionView.subview

【iOS开发-56】案例BUG:button的enabled、控件的userInteractionEnabled以及两种提示框UIAlert和UIActionSheet

接上述案例找BUG:[iOS开发-51]案例学习:动画新写法.删除子视图.视图顺序.延迟方法.button多功能使用方法及icon图标和启动页设置 (1)BUG:答案满了就不能再点击optionbutton,答案没满就能点. 在optionClick方法的if(full)中设置,即推断答案是否满了,假设满了.则: if (full) { //假设答案满了,无论是否正确,仅仅要满了,以下的optionbutton就不能被点击 for (UIButton *optionBtn in self.opt

提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果 2014-08-11 17:39 11614人阅读 评论(0) 收藏 举报  分类: iOS相关(20)  文章来自:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显示的内容进行自定义,功能很强大,很多项目中都有使用到.到GitHub上可以下载到项目源码

关于iOS中提示框的使用

关于iOS中提示框的使用在iOS8的SDK里,已经对提示框进行了更改,现在属于 UIAlertController,其接口如下声明NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController,不再是一个UIView. 具体的使用如下,希望对某些朋友有帮助.#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0 //判断你当前的iOS SDK所支持的最大iOS系

自适应文案提示框、无数据图片加载<IOS小组件>

非常感谢,帮助我的朋友们,谢谢你们. 该组件的编写仅仅用来不到4个小时,包括测试与修改bug.为他起名为AdaptivePromptDialogBox(就是自适应文案提示框): 呆毛地址:https://github.com/NIUXINGJIAN/AdaptivePromptDialogBox.git [创作背景]:今天服务器返回的提示文案过于长,原来自定义实现的黑框效果不能满足.我想办法去让他自适应宽度和高度.在做到页面无数图片加载的时候,我自己封装了一个方法,用起来很好用,决定将其定为该方

iOS提示框之 MBProgressHUD 与 SVProgressHUD

提示框,进度提示,加载中提示等等,无论怎样,你总是需要提示框来指示某个状态正在后台努力进行中.一个合适的提示框,更多的是用来增强用户体验.把最多的时间,用来做更核心的事;把这些不是非常重要的事,你应该试着使用一个成熟稳定的第三方来解决. MBProgressHUD还是 SVProgressHUD ? 许多时候,选择都是很重要的,但是总是要做出选择.每个人考虑的因素和角度不同,结论或许也不同.但是,你要明白,你现在是要找一个合适的方案来解决自己的关于"提示框"的需求,而不是去无意义的讨论

iOS - UIAlertController三种显示提示框代码

UIAlertView在IOS 8以上版本已经过时了,官方推荐我们使用UIAlertController代替UIAlertView.UIActionSheet 1?UIAlertController显示普通的Alert - (IBAction)showAlert:(UIButton *)sender { //显示提示框 //过时 // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@&q