自定义同时有图片文字的提示框
来源:互联网 发布:愚人节整人软件 编辑:程序博客网 时间:2024/05/26 19:15
废话不多说,代码都能看懂,
.h文件
//
// XJAlertView.h
// XiaoQiao
//
// Created by 王小胜 on 2017/6/20.
// Copyright © 2017年 Ningbo Xiaojiang IOT Technology Co., LTD. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef void(^alertViewSureBlock)();
@interface XJAlertView : UIView
@property(nonatomic,copy)alertViewSureBlock block;
+ (instancetype)sharedAlertView;
//快速显示
- (void)alertViewMessage :(NSString *)message cancelTitle:(NSString *)cancelTitle sureTitle:(NSString *)sureTitle image:(NSString *)image Block:(alertViewSureBlock)block;
@end
.m文件
//
// XJAlertView.m
// XiaoQiao
//
// Created by 王小胜 on 2017/6/20.
// Copyright © 2017年 Ningbo Xiaojiang IOT Technology Co., LTD. All rights reserved.
//
#import "XJAlertView.h"
#import "Masonry.h"
#define kColor(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1]
@interface XJAlertView (){
NSString * sureTitles;
NSString * cancelTitles;
NSString * messages;
NSString * titleimage;
}
@property(nonatomic,strong)UIButton *canBtn;
@property(nonatomic,strong)UIButton *sureBtn;
@property(nonatomic,strong)UILabel *messageLable;
@property(nonatomic,strong)UIImageView * images;
@property(nonatomic,strong)UIView *showView;
@property(nonatomic,strong)UIView *levelView;
@property(nonatomic,strong)UIView *verticalView;
@end
@implementation XJAlertView
static id _alertView =nil;
+ (instancetype)sharedAlertView{
return [[selfalloc]init];;
}
- (instancetype)init{
if (self == [superinit]) {
[selfsetUpframe];
}
returnself;
}
- (void)layoutSubviews{
[superlayoutSubviews];
if (cancelTitles !=nil) {
[self.canBtnmas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.frame.size.width/2);
make.height.mas_equalTo(60);
make.bottom.left.mas_equalTo(self);
}];
}
if (sureTitles !=nil) {
[self.sureBtnmas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.frame.size.width/2);
make.height.mas_equalTo(60);
make.bottom.right.mas_equalTo(self);
}];
}
if (titleimage !=nil) {
[self.imagesmas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(120);
make.height.mas_equalTo(120);
make.top.mas_equalTo(self);
make.centerX.equalTo(self);
}];
}
if (messages !=nil) {
[self.messageLablemas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30);
make.left.mas_equalTo(self).offset(5);
make.right.mas_equalTo(self).offset(-5);
make.top.mas_equalTo(self).offset(125);
}];
}
[self.levelViewmas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self);
make.right.mas_equalTo(self);
make.height.mas_equalTo(1);
make.top.mas_equalTo(self.frame.size.height -60);
}];
[self.verticalViewmas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.frame.size.width/2-1);
make.width.mas_equalTo(1);
make.bottom.mas_equalTo(self);
make.top.mas_equalTo(self.frame.size.height -60);
}];
}
- (void)setUpframe{
self.showView = [[UIViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
self.showView.backgroundColor = [UIColorcolorWithRed:0green:0blue:0alpha:0.5];
[[UIApplicationsharedApplication].keyWindowaddSubview:self.showView];
[self.showViewaddSubview:self];
self.backgroundColor = [UIColorwhiteColor];
self.layer.cornerRadius =5;
self.layer.masksToBounds =YES;
self.backgroundColor = [UIColorwhiteColor];
self.frame =CGRectMake(0,0,280,240);
self.center =CGPointMake([UIScreenmainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2);
_canBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
_canBtn.titleLabel.font = [UIFontsystemFontOfSize:19.0f];
[_canBtnsetTitleColor:kColor(165,166,167) forState:UIControlStateNormal];
[_canBtnaddTarget:selfaction:@selector(cancelTitle)forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:_canBtn];
_sureBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
_sureBtn.titleLabel.font = [UIFontsystemFontOfSize:19.0f];
[_sureBtnsetTitleColor:kColor(81,128,217) forState:UIControlStateNormal];
[_sureBtnaddTarget:selfaction:@selector(sureTitle)forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:_sureBtn];
_messageLable = [[UILabelalloc]init];
_messageLable.textAlignment =NSTextAlignmentCenter;
_messageLable.font = [UIFontsystemFontOfSize:16.0f];
_messageLable.numberOfLines =0;
[selfaddSubview:_messageLable];
_images = [[UIImageViewalloc]init];
[selfaddSubview:_images];
_levelView = [[UIViewalloc]init];
_levelView.backgroundColor =kColor(231,232,233);
[selfaddSubview:_levelView];
_verticalView = [[UIViewalloc]init];
_verticalView.backgroundColor =kColor(231,232,233);
[selfaddSubview:_verticalView];
}
- (void)alertViewMessage:(NSString *)message cancelTitle:(NSString *)cancelTitle sureTitle:(NSString *)sureTitle image:(NSString *)image Block:(alertViewSureBlock)block{
cancelTitles = cancelTitle;
sureTitles = sureTitle;
titleimage = image;
messages = message;
self.block = block;
[_canBtnsetTitle:cancelTitlesforState:UIControlStateNormal];
[_sureBtnsetTitle:sureTitlesforState:UIControlStateNormal];
_messageLable.text =messages;
_images.image = [UIImageimageNamed:titleimage];
}
- (void)cancelTitle{
[self.showViewremoveFromSuperview];
}
- (void)sureTitle{
self.block();
[self.showViewremoveFromSuperview];
}
@end
XJAlertView * alert = [XJAlertViewsharedAlertView];
[alert alertViewMessage:@"欢迎使用,这是一个自定义的弹出框,你可以加上其它功能,这只是一个测试!"cancelTitle:@"取消"sureTitle:@"确定"image:@"run_icon"Block:^{
NSLog(@"123");
}];
- 自定义同时有图片文字的提示框
- 按钮上同时有文字和图片
- 自定义button同时显示文字和图片
- 文字和图片同时提交 提示图片不完整
- 表单图片文字同时上传的解决方法
- Android自定义组件,实现图片和文字同时显示
- 自定义控件使用DrawableLeft/Right图片和文字同时居中
- 自定义控件使用DrawableLeft/Right图片和文字同时居中
- 图片 文字 同时滚动
- 修改ASPxGridView的提示No data to display为图片或自定义文字
- UIButton 同时显示图片文字 |-图片-文字-|
- html5自定义required的提示文字
- 同时缩放文字与图片
- 同时上传图片与文字
- 自定义一个图片加文字button,点击有效果
- 显示 图片+文字 提示
- asp 批量同时上传文字和图片的实现。
- UIButton上同时显示图片和文字的方法
- Vuforia的学习(六)DefaultTrackableEventHandler脚本解析
- 在Fedora 25上编译SELinux Policy
- angular2语法总结
- 递归-角谷定理
- redis使用watch秒杀抢购思路
- 自定义同时有图片文字的提示框
- mysql常用监控脚本命令整理
- 仿简书动态 searchview 的实现,代码就这么多点
- SimpleDateFormat安全的使用方法
- IntelliJ IDEA 注册码
- 安卓逆向之陕西网络安全大赛第三题
- Linux 通配符
- extjs radiogroup 动态选中
- intellij idea 配置sublime主题