Brak opisu

FKBuyRemindView.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // FKBuyRemindView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/9/17.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBuyRemindView.h"
  9. #import "FKTargetConfigUtil.h"
  10. @interface FKBuyRemindView ()
  11. @property (nonatomic, strong) UIImageView *contentView;
  12. @property (nonatomic, strong) UILabel *titleLabel;
  13. @property (nonatomic, strong) UIButton *topBtn;
  14. @property (nonatomic, strong) UIButton *downBtn;
  15. @property (nonatomic, strong) UIButton *cancelBtn;
  16. @end
  17. @implementation FKBuyRemindView
  18. - (instancetype)initWithFrame:(CGRect)frame{
  19. if (self = [super initWithFrame:frame]) {
  20. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
  21. [self addAllSubViews];
  22. }
  23. return self;
  24. }
  25. - (void)addAllSubViews{
  26. [self addSubview:self.contentView];
  27. [self addSubview:self.cancelBtn];
  28. [self.contentView addSubview:self.titleLabel];
  29. [self.contentView addSubview:self.topBtn];
  30. [self.contentView addSubview:self.downBtn];
  31. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.center.equalTo(self);
  33. }];
  34. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.top.equalTo(self.contentView).offset(127.5 + 25);
  36. make.left.equalTo(self.contentView).offset(25);
  37. make.right.equalTo(self.contentView).offset(- 25);
  38. }];
  39. [self.downBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.bottom.equalTo(self.contentView).offset(- 40);
  41. make.left.right.equalTo(self.titleLabel);
  42. make.width.mas_equalTo(185);
  43. make.height.mas_equalTo(28);
  44. }];
  45. [self.topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.bottom.equalTo(self.downBtn.mas_top).offset(- 20);
  47. make.left.right.equalTo(self.titleLabel);
  48. make.width.height.equalTo(self.downBtn);
  49. }];
  50. [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.centerX.equalTo(self.contentView.mas_right);
  52. make.centerY.equalTo(self.contentView.mas_top);
  53. make.width.height.mas_equalTo(50);
  54. }];
  55. }
  56. - (void)showInView:(UIView *)view{
  57. if (!view) return;
  58. UIWindow *window = view.window;
  59. if (window){
  60. for (UIView *subView in window.subviews) {
  61. if ([subView isKindOfClass:[FKBuyRemindView class]]){
  62. [subView removeFromSuperview];
  63. break;
  64. }
  65. }
  66. [window addSubview:self];
  67. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.edges.insets(UIEdgeInsetsZero);
  69. }];
  70. self.alpha = 0;
  71. [UIView animateWithDuration:0.3f animations:^{
  72. self.alpha = 1.0f;
  73. }];
  74. }
  75. }
  76. #pragma mark - action
  77. - (void)clickCancelBtn{
  78. WeakSelf(weakSelf);
  79. [UIView animateWithDuration:0.3f animations:^{
  80. weakSelf.alpha = 0;
  81. } completion:^(BOOL finished) {
  82. [weakSelf removeFromSuperview];
  83. }];
  84. }
  85. - (void)clickActionBtn:(UIButton *)sender{
  86. WeakSelf(weakSelf);
  87. NSUInteger tag = sender.tag;
  88. [UIView animateWithDuration:0.3f animations:^{
  89. weakSelf.alpha = 0;
  90. } completion:^(BOOL finished) {
  91. if (tag == 0) {
  92. if ([weakSelf.delegate respondsToSelector:@selector(remindViewClickToBuy:)]){
  93. [weakSelf.delegate remindViewClickToBuy:self];
  94. }
  95. }else if (tag == 1){
  96. if ([weakSelf.delegate respondsToSelector:@selector(remindViewClickToRemind:)]){
  97. [weakSelf.delegate remindViewClickToRemind:self];
  98. }
  99. }
  100. [weakSelf removeFromSuperview];
  101. }];
  102. }
  103. #pragma mark - property
  104. - (UIImageView *)contentView{
  105. if (_contentView == nil) {
  106. _contentView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"vipBg.jpg"]];
  107. _contentView.userInteractionEnabled = YES;
  108. }
  109. return _contentView;
  110. }
  111. - (UILabel *)titleLabel{
  112. if (_titleLabel == nil) {
  113. _titleLabel = [[UILabel alloc]init];
  114. _titleLabel.font = [UIFont systemFontOfSize:14];
  115. _titleLabel.textColor = UIColorFromRGB(0xffffff);
  116. _titleLabel.text = @"当前拼单已结束,您可以选择开通VIP会员服务,请您的管家立刻帮您购买;也可以开启拼单提醒,等待下次拼单。";
  117. _titleLabel.numberOfLines = 0;
  118. }
  119. return _titleLabel;
  120. }
  121. - (UIButton *)topBtn{
  122. if (_topBtn == nil) {
  123. _topBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  124. _topBtn.backgroundColor = [UIColorFromRGB(0x00c8a9) colorWithAlphaComponent:0.85];
  125. _topBtn.layer.cornerRadius = 14;
  126. _topBtn.tag = 0;
  127. _topBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  128. [_topBtn setTitle:@"开通VIP会员服务" forState:UIControlStateNormal];
  129. [_topBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  130. [_topBtn addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
  131. }
  132. return _topBtn;
  133. }
  134. - (UIButton *)downBtn{
  135. if (_downBtn == nil) {
  136. _downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  137. _downBtn.backgroundColor = [UIColorFromRGB(0x00c8a9) colorWithAlphaComponent:0.85];
  138. _downBtn.layer.cornerRadius = 14;
  139. _downBtn.tag = 1;
  140. _downBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  141. [_downBtn setTitle:@"拼单开始提醒我" forState:UIControlStateNormal];
  142. [_downBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  143. [_downBtn addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
  144. }
  145. return _downBtn;
  146. }
  147. - (UIButton *)cancelBtn{
  148. if (_cancelBtn == nil) {
  149. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  150. [_cancelBtn setImage:[UIImage imageNamed:@"cancelBtnBg"] forState:UIControlStateNormal];
  151. [_cancelBtn addTarget:self action:@selector(clickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
  152. }
  153. return _cancelBtn;
  154. }
  155. - (void)setIsVip:(BOOL)isVip{
  156. _isVip = isVip;
  157. if (_isVip == YES){
  158. [self.topBtn setTitle:@"马上找管家购买" forState:UIControlStateNormal];
  159. self.titleLabel.text = [NSString stringWithFormat:@"当前拼单已结束,您已经是%@VIP会员,可以马上找管家帮您购买;也可以开启拼单提醒,等待下次拼单。", [FKTargetConfigUtil appName]];
  160. }else{
  161. [self.topBtn setTitle:@"开通VIP会员服务" forState:UIControlStateNormal];
  162. self.titleLabel.text = @"当前拼单已结束,您可以选择开通VIP会员服务,请您的管家立刻帮您购买;也可以开启拼单提醒,等待下次拼单。";
  163. }
  164. }
  165. @end