1想虎、彈出屏蔽罩一般用在提示用戶一些重要信息卦尊,和系統(tǒng)自帶的UIAlertController起到一樣的效果,只不過自定義屏蔽罩彈窗可以使內(nèi)容更加多元化
2舌厨、代碼如下
#import <UIKit/UIKit.h>
@class LZExchangeCouponView, BeanCoupon;
@protocol LZExchangeCouponViewDelegate <NSObject>
@optional
/**
* 確定按鈕代理方法
*/
- (void)exchangeCouponViewDelegate:(LZExchangeCouponView *) exchangeCouponView addDefineButton:(UIButton *)defineButton;
/**
* 關(guān)閉按鈕代理方法
*/
- (void)exchangeCouponViewDelegate:(LZExchangeCouponView *)exchangeCouponView addColseButton:(UIButton *)colseButton;
@end
@interface LZExchangeCouponView : UIView
/**
* 兌換券對象
*/
@property (nonatomic, strong) BeanCoupon *coupon;
/**
* 兌換券代理
*/
@property (nonatomic, weak) id<LZExchangeCouponViewDelegate> delegate;
@end
#import "LZExchangeCouponView.h"
#import "bean/Coupon.h"
@interface LZExchangeCouponView ()
/**
* 透明背景View
*/
@property (nonatomic, strong) UIView *bgView;
/**
* contentView
*/
@property (nonatomic, strong) UIView *couponBgView;
/**
* 背景圖片
*/
@property (nonatomic, strong) UIImageView *bgImageView;
/**
* 兌換券圖片
*/
@property (nonatomic, strong) UIImageView *exchangeImageView;
/**
* 兌換券提示
*/
@property (nonatomic, strong) UILabel *tsLabel;
/**
* 兌換天數(shù)
*/
@property (nonatomic, strong) UILabel *exchangeLabel;
/**
* 確定按鈕
*/
@property (nonatomic, strong) UIButton *defineButton;
/**
* 關(guān)閉按鈕
*/
@property (nonatomic, strong) UIButton *closeButton;
@end
@implementation LZExchangeCouponView
#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
//0岂却、透明View
self.bgView = [[UIView alloc] init];
self.bgView.backgroundColor = [UIColor blackColor];
self.bgView.alpha = 0.5;
[self addSubview:self.bgView];
//1、contentView
self.couponBgView = [[UIView alloc] init];
// self.couponBgView.backgroundColor = [UIColor whiteColor];
[self addSubview:self.couponBgView];
//2裙椭、背景圖片
self.bgImageView = [[UIImageView alloc] init];
self.bgImageView.image = [UIImage imageNamed:@"coupon_bg"];
[self.couponBgView addSubview:self.bgImageView];
//3躏哩、兌換券圖片
self.exchangeImageView = [[UIImageView alloc] init];
[self.couponBgView addSubview:self.exchangeImageView];
//4、兌換券提示
self.tsLabel = [[UILabel alloc] init];
self.tsLabel.text = @"是否現(xiàn)在使用該券";
self.tsLabel.textAlignment = NSTextAlignmentCenter;
self.tsLabel.font = [UIFont systemFontOfSize:13.0];
self.tsLabel.textColor = RWTitleColor(0, 0, 0);
[self.couponBgView addSubview:self.tsLabel];
//5揉燃、兌換天數(shù)
self.exchangeLabel = [[UILabel alloc] init];
// self.exchangeLabel.text = @"為您開通 7 天的VIP會員";
self.exchangeLabel.textAlignment = NSTextAlignmentCenter;
self.exchangeLabel.font = [UIFont systemFontOfSize:15.0];
self.exchangeLabel.textColor = RWTitleColor(107, 113, 113);
[self.couponBgView addSubview:self.exchangeLabel];
//6扫尺、確定按鈕
self.defineButton = [[UIButton alloc] init];
[self.defineButton setTitle:@"確定使用" forState:UIControlStateNormal];
[self.defineButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.defineButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
self.defineButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.defineButton setBackgroundImage:[UIImage imageNamed:@"coupon_queding"] forState:UIControlStateNormal];
//確定按鈕事件
[self.defineButton addTarget:self action:@selector(defineButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.couponBgView addSubview:self.defineButton];
//7、關(guān)閉按鈕
self.closeButton = [[UIButton alloc] init];
[self.closeButton setImage:[UIImage imageNamed:@"coupon_close"] forState:UIControlStateNormal];
//關(guān)閉按鈕事件
[self.closeButton addTarget:self action:@selector(closeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.couponBgView addSubview:self.closeButton];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
//防止在block中循環(huán)引用
__unsafe_unretained __typeof(self) weakSelf = self;
//0炊汤、透明背景View
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.bottom.mas_equalTo(0);
}];
//1正驻、背景View
[self.couponBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(weakSelf.mas_centerX);
make.centerY.mas_equalTo(weakSelf.mas_centerY);
make.width.mas_equalTo(302);
make.height.mas_equalTo(247);
}];
//2、背景圖片
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(0);
make.right.mas_equalTo(0);
}];
//3抢腐、兌換券圖片
[self.exchangeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.height.mas_equalTo(100);
}];
//4拨拓、兌換券提示
[self.tsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(weakSelf.exchangeImageView.mas_bottom).offset(20);
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.height.mas_equalTo(20);
}];
//5、兌換天數(shù)
[self.exchangeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(weakSelf.tsLabel.mas_bottom).offset(10);
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.height.mas_equalTo(30);
}];
//6氓栈、確定按鈕
[self.defineButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-8);
make.left.mas_equalTo(30);
make.height.mas_equalTo(40);
make.right.mas_equalTo(-30);
}];
//7渣磷、關(guān)閉按鈕
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(270);
make.top.mas_equalTo(-25);
make.height.mas_equalTo(50);
make.width.mas_equalTo(50);
}];
}
#pragma mark - 關(guān)閉按鈕事件
/**
* 關(guān)閉按鈕事件
*/
- (void)closeButtonClick:(UIButton *) closeButton {
NSLog(@"點(diǎn)擊了關(guān)閉按鈕");
if ([self.delegate respondsToSelector:@selector(exchangeCouponViewDelegate:addColseButton:)]) {
[self.delegate exchangeCouponViewDelegate:self addColseButton:closeButton];
}
}
#pragma mark - 確定按鈕事件
/**
* 確定按鈕事件
*/
- (void)defineButtonClick:(UIButton *) defineButton {
NSLog(@"點(diǎn)擊了確定按鈕");
if ([self.delegate respondsToSelector:@selector(exchangeCouponViewDelegate:addDefineButton:)]) {
[self.delegate exchangeCouponViewDelegate:self addDefineButton:defineButton];
}
}
- (void)setCoupon:(BeanCoupon *)coupon {
_coupon = coupon;
//設(shè)置兌換圖片
[self.exchangeImageView sd_setImageWithURL:[NSURL URLWithString:[coupon getCouponSmallImgUrl]] placeholderImage:[UIImage imageNamed:@"imgMid"]];
//設(shè)置兌換天數(shù)
self.exchangeLabel.text = [NSString stringWithFormat:@"為您開通%@天的VIP會員", [coupon getVipDays]];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者