美文网首页
06-屏蔽罩

06-屏蔽罩

作者: 紫荆秋雪_文 | 来源:发表于2016-10-28 11:37 被阅读9次

1、弹出屏蔽罩一般用在提示用户一些重要信息,和系统自带的UIAlertController起到一样的效果,只不过自定义屏蔽罩弹窗可以使内容更加多元化

2、代码如下


#import <UIKit/UIKit.h>
@class LZExchangeCouponView, BeanCoupon;

@protocol LZExchangeCouponViewDelegate <NSObject>

@optional

/**
 * 确定按钮代理方法
 */
- (void)exchangeCouponViewDelegate:(LZExchangeCouponView *) exchangeCouponView addDefineButton:(UIButton *)defineButton;

/**
 * 关闭按钮代理方法
 */
- (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;

/**
 *  兑换天数
 */
@property (nonatomic, strong) UILabel *exchangeLabel;

/**
 *  确定按钮
 */
@property (nonatomic, strong) UIButton *defineButton;

/**
 *  关闭按钮
 */
@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 = @"是否现在使用该券";
        self.tsLabel.textAlignment = NSTextAlignmentCenter;
        self.tsLabel.font = [UIFont systemFontOfSize:13.0];
        self.tsLabel.textColor = RWTitleColor(0, 0, 0);
        [self.couponBgView addSubview:self.tsLabel];
        
        //5、兑换天数
        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、关闭按钮
        self.closeButton = [[UIButton alloc] init];
        [self.closeButton setImage:[UIImage imageNamed:@"coupon_close"] forState:UIControlStateNormal];
        //关闭按钮事件
        [self.closeButton addTarget:self action:@selector(closeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.couponBgView addSubview:self.closeButton];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    //防止在block中循环引用
    __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、兑换天数
    [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、关闭按钮
    [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 - 关闭按钮事件
/**
 * 关闭按钮事件
 */
- (void)closeButtonClick:(UIButton *) closeButton {
    NSLog(@"点击了关闭按钮");
    if ([self.delegate respondsToSelector:@selector(exchangeCouponViewDelegate:addColseButton:)]) {
        [self.delegate exchangeCouponViewDelegate:self addColseButton:closeButton];
    }
}

#pragma mark - 确定按钮事件
/**
 * 确定按钮事件
 */
- (void)defineButtonClick:(UIButton *) defineButton {
    NSLog(@"点击了确定按钮");
    if ([self.delegate respondsToSelector:@selector(exchangeCouponViewDelegate:addDefineButton:)]) {
        [self.delegate exchangeCouponViewDelegate:self addDefineButton:defineButton];
    }

}

- (void)setCoupon:(BeanCoupon *)coupon {
    _coupon = coupon;
    //设置兑换图片
    [self.exchangeImageView sd_setImageWithURL:[NSURL URLWithString:[coupon getCouponSmallImgUrl]] placeholderImage:[UIImage imageNamed:@"imgMid"]];
    
    //设置兑换天数
    self.exchangeLabel.text = [NSString stringWithFormat:@"为您开通%@天的VIP会员", [coupon getVipDays]];
}

相关文章

  • 06-屏蔽罩

    1、弹出屏蔽罩一般用在提示用户一些重要信息,和系统自带的UIAlertController起到一样的效果,只不过自...

  • 铜箔胶带电磁屏蔽罩设计案例

    铜箔胶带屏蔽罩是用来屏蔽电子信号的工具。作用就是屏蔽外接电磁波对内部电路的影响和内部产生的电磁波向外辐射。 屏蔽罩...

  • 想要为你带上屏蔽罩

    从九月初离开原来的部门任现在这个特别的职位,已经四个月过去了。当有人问起K小姐,她总傻乎乎的笑着说,还行,挺好的。...

  • 能量罩

    今天突然脑洞大开在想能量罩的形成。 以前在电影里经常看到能量罩的出现,集防御与屏蔽,甚至隐身于一体的能量形式存在的...

  • hitTest的作用与用法

    hitTest的作用: hitTest的用法:将下面的函数添加到UIView的子类中,也就是屏蔽罩类中即可。 Ui...

  • 如何戴上能量金钟罩屏蔽疫情感染

    面对严峻的疫情感染,单纯从物质层面去做防护,这就足够了吗?防口的同时也要防心❣️,你知道如何给自己的心戴上能量金钟...

  • 罩罩和苗苗

    罩罩和苗苗,到底哪个好?百思不得其解,犹如王阳明格竹子,想破脑袋也想不出。只好去看看,不过看到的也不一定是真的,那...

  • 《罩》

    《罩》 你,无一不是重叠的 换一种方式坠落 人行冗长,拒绝千年前的安静 在一片风月里,绵软而僵硬 月晕,蒙上一层暗...

  • 婚姻像口罩 戴的人算有了保护 不戴的人也就没了束缚 人类绞尽脑汁 设计出林林总总的制度 嘿嘿——想的美呢! 婚姻真...

  • 罩下的世界怎会陌生 大气层底下活了几千年 罩内自有空气和空间 翻山到罩外呼吸是为甚么 如果不敢抽一口无毒的凉风 因...

网友评论

      本文标题:06-屏蔽罩

      本文链接:https://www.haomeiwen.com/subject/hvxeuttx.html