123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // FKBuyRemindView.m
- // FirstLink
- //
- // Created by jack on 15/9/17.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "FKBuyRemindView.h"
- #import "FKTargetConfigUtil.h"
- @interface FKBuyRemindView ()
- @property (nonatomic, strong) UIImageView *contentView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UIButton *topBtn;
- @property (nonatomic, strong) UIButton *downBtn;
- @property (nonatomic, strong) UIButton *cancelBtn;
- @end
- @implementation FKBuyRemindView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
- [self addAllSubViews];
- }
- return self;
- }
- - (void)addAllSubViews{
-
- [self addSubview:self.contentView];
- [self addSubview:self.cancelBtn];
- [self.contentView addSubview:self.titleLabel];
- [self.contentView addSubview:self.topBtn];
- [self.contentView addSubview:self.downBtn];
-
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self);
- }];
-
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(127.5 + 25);
- make.left.equalTo(self.contentView).offset(25);
- make.right.equalTo(self.contentView).offset(- 25);
- }];
-
- [self.downBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.contentView).offset(- 40);
- make.left.right.equalTo(self.titleLabel);
- make.width.mas_equalTo(185);
- make.height.mas_equalTo(28);
- }];
-
- [self.topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.downBtn.mas_top).offset(- 20);
- make.left.right.equalTo(self.titleLabel);
- make.width.height.equalTo(self.downBtn);
- }];
-
- [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.contentView.mas_right);
- make.centerY.equalTo(self.contentView.mas_top);
- make.width.height.mas_equalTo(50);
- }];
- }
- - (void)showInView:(UIView *)view{
- if (!view) return;
-
- UIWindow *window = view.window;
- if (window){
-
- for (UIView *subView in window.subviews) {
- if ([subView isKindOfClass:[FKBuyRemindView class]]){
- [subView removeFromSuperview];
- break;
- }
- }
-
- [window addSubview:self];
-
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
-
- self.alpha = 0;
-
- [UIView animateWithDuration:0.3f animations:^{
- self.alpha = 1.0f;
- }];
- }
-
- }
- #pragma mark - action
- - (void)clickCancelBtn{
-
- WeakSelf(weakSelf);
- [UIView animateWithDuration:0.3f animations:^{
- weakSelf.alpha = 0;
- } completion:^(BOOL finished) {
- [weakSelf removeFromSuperview];
- }];
- }
- - (void)clickActionBtn:(UIButton *)sender{
- WeakSelf(weakSelf);
- NSUInteger tag = sender.tag;
-
- [UIView animateWithDuration:0.3f animations:^{
- weakSelf.alpha = 0;
- } completion:^(BOOL finished) {
- if (tag == 0) {
- if ([weakSelf.delegate respondsToSelector:@selector(remindViewClickToBuy:)]){
- [weakSelf.delegate remindViewClickToBuy:self];
- }
- }else if (tag == 1){
- if ([weakSelf.delegate respondsToSelector:@selector(remindViewClickToRemind:)]){
- [weakSelf.delegate remindViewClickToRemind:self];
- }
- }
- [weakSelf removeFromSuperview];
- }];
- }
- #pragma mark - property
- - (UIImageView *)contentView{
- if (_contentView == nil) {
- _contentView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"vipBg.jpg"]];
- _contentView.userInteractionEnabled = YES;
- }
- return _contentView;
- }
- - (UILabel *)titleLabel{
- if (_titleLabel == nil) {
- _titleLabel = [[UILabel alloc]init];
- _titleLabel.font = [UIFont systemFontOfSize:14];
- _titleLabel.textColor = UIColorFromRGB(0xffffff);
- _titleLabel.text = @"当前拼单已结束,您可以选择开通VIP会员服务,请您的管家立刻帮您购买;也可以开启拼单提醒,等待下次拼单。";
- _titleLabel.numberOfLines = 0;
- }
- return _titleLabel;
- }
- - (UIButton *)topBtn{
- if (_topBtn == nil) {
- _topBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _topBtn.backgroundColor = [UIColorFromRGB(0x00c8a9) colorWithAlphaComponent:0.85];
- _topBtn.layer.cornerRadius = 14;
- _topBtn.tag = 0;
- _topBtn.titleLabel.font = [UIFont systemFontOfSize:14];
- [_topBtn setTitle:@"开通VIP会员服务" forState:UIControlStateNormal];
- [_topBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
- [_topBtn addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _topBtn;
- }
- - (UIButton *)downBtn{
- if (_downBtn == nil) {
- _downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _downBtn.backgroundColor = [UIColorFromRGB(0x00c8a9) colorWithAlphaComponent:0.85];
- _downBtn.layer.cornerRadius = 14;
- _downBtn.tag = 1;
- _downBtn.titleLabel.font = [UIFont systemFontOfSize:14];
- [_downBtn setTitle:@"拼单开始提醒我" forState:UIControlStateNormal];
- [_downBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
- [_downBtn addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _downBtn;
- }
- - (UIButton *)cancelBtn{
- if (_cancelBtn == nil) {
- _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_cancelBtn setImage:[UIImage imageNamed:@"cancelBtnBg"] forState:UIControlStateNormal];
- [_cancelBtn addTarget:self action:@selector(clickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
- }
- return _cancelBtn;
- }
- - (void)setIsVip:(BOOL)isVip{
- _isVip = isVip;
- if (_isVip == YES){
- [self.topBtn setTitle:@"马上找管家购买" forState:UIControlStateNormal];
- self.titleLabel.text = [NSString stringWithFormat:@"当前拼单已结束,您已经是%@VIP会员,可以马上找管家帮您购买;也可以开启拼单提醒,等待下次拼单。", [FKTargetConfigUtil appName]];
- }else{
- [self.topBtn setTitle:@"开通VIP会员服务" forState:UIControlStateNormal];
- self.titleLabel.text = @"当前拼单已结束,您可以选择开通VIP会员服务,请您的管家立刻帮您购买;也可以开启拼单提醒,等待下次拼单。";
- }
- }
- @end
|