暫無描述

FKExitRemindView.m 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // FKExitOrdersRemindView.m
  3. // FirstLink
  4. //
  5. // Created by 施昌鹏 on 16/7/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKExitRemindView.h"
  9. @interface FKExitRemindView ()
  10. @property (nonatomic, strong) UIView *bgView;
  11. @property (nonatomic, strong) UIImageView *cartoonImageView;
  12. @property (nonatomic, strong) UILabel *titleLabel;
  13. @property (nonatomic, strong) UIButton *confirmButton;
  14. @property (nonatomic, strong) UIButton *cancelButton;
  15. @property (nonatomic, strong) UIView *divideViewH;
  16. @property (nonatomic, strong) UIView *divideViewV;
  17. @end
  18. @implementation FKExitRemindView
  19. -(instancetype)initWithFrame:(CGRect)frame {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. [self addSubviews];
  23. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
  24. }
  25. return self;
  26. }
  27. -(void)addSubviews {
  28. [self addSubview:self.bgView];
  29. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.center.equalTo(self);
  31. make.height.mas_equalTo(130);
  32. make.width.mas_equalTo(255);
  33. }];
  34. [self addSubview:self.cartoonImageView];
  35. [self.cartoonImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.centerX.equalTo(self.bgView.mas_centerX);
  37. make.bottom.equalTo(self.bgView.mas_top).offset(23);
  38. }];
  39. [self.bgView addSubview:self.titleLabel];
  40. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.left.right.equalTo(self.bgView);
  42. make.height.mas_equalTo(80);
  43. }];
  44. [self.bgView addSubview:self.confirmButton];
  45. [self.bgView addSubview:self.cancelButton];
  46. [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.right.bottom.equalTo(self.bgView);
  48. make.top.equalTo(self.titleLabel.mas_bottom).offset(0.5);
  49. make.left.equalTo(self.confirmButton.mas_right).offset(0.5);
  50. make.width.equalTo(self.confirmButton);
  51. }];
  52. [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.bottom.equalTo(self.bgView);
  54. make.top.equalTo(self.cancelButton);
  55. make.width.equalTo(self.cancelButton);
  56. }];
  57. [self.bgView addSubview:self.divideViewH];
  58. [self.divideViewH mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.right.equalTo(self.bgView);
  60. make.top.equalTo(self.titleLabel.mas_bottom);
  61. make.height.mas_equalTo(0.5);
  62. }];
  63. [self.bgView addSubview:self.divideViewV];
  64. [self.divideViewV mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.equalTo(self.divideViewH.mas_bottom);
  66. make.bottom.equalTo(self.bgView);
  67. make.centerX.equalTo(self.bgView);
  68. make.width.mas_equalTo(0.5);
  69. }];
  70. }
  71. + (instancetype)initWithTitleString:(NSString *)titleString confirmButtonText:(NSString *)confirmText cancelButtonText:(NSString *)cancelText{
  72. FKExitRemindView *view = [[FKExitRemindView alloc]init];
  73. view.titleLabel.text = titleString;
  74. [view.confirmButton setTitle:confirmText forState:UIControlStateNormal];
  75. [view.cancelButton setTitle:cancelText forState:UIControlStateNormal];
  76. return view;
  77. }
  78. -(void)clickButton:(UIButton *)button {
  79. self.alpha = 1.0f;
  80. if ([_delegate respondsToSelector:@selector(exitRemindView:clickedButtonAtIndex:)]) {
  81. [_delegate exitRemindView:self clickedButtonAtIndex:button.tag];
  82. }
  83. WeakSelf(weakSelf);
  84. [UIView animateWithDuration:0.3f animations:^{
  85. weakSelf.alpha = 0;
  86. } completion:^(BOOL finished) {
  87. [weakSelf removeFromSuperview];
  88. }];
  89. }
  90. -(void)showInView:(UIView *)view {
  91. UIWindow *window = view.window;
  92. [window addSubview:self];
  93. self.alpha = 0;
  94. self.frame = CGRectMake(0, 0, window.bounds.size.width, window.bounds.size.height);
  95. WeakSelf(weakSelf);
  96. [UIView animateWithDuration:0.3f animations:^{
  97. weakSelf.alpha = 1.0;
  98. } completion:nil];
  99. }
  100. - (void)setLogoHidden:(BOOL)hidden {
  101. self.cartoonImageView.hidden = hidden;
  102. }
  103. #pragma mark - get
  104. -(UIView *)bgView {
  105. if (_bgView == nil) {
  106. _bgView = [[UIView alloc] init];
  107. _bgView.backgroundColor = [UIColor whiteColor];
  108. _bgView.layer.cornerRadius = 8.0;
  109. }
  110. return _bgView;
  111. }
  112. -(UIImageView *)cartoonImageView {
  113. if (_cartoonImageView == nil) {
  114. UIImage *cartoonImage = [UIImage imageNamed:@"cartoon_icon"];
  115. _cartoonImageView = [[UIImageView alloc] initWithImage:cartoonImage];
  116. }
  117. return _cartoonImageView;
  118. }
  119. -(UILabel *)titleLabel {
  120. if (_titleLabel == nil) {
  121. _titleLabel = [[UILabel alloc] init];
  122. _titleLabel.font = [UIFont systemFontOfSize:15.0];
  123. _titleLabel.textColor = UIColorFromRGB(0x333333);
  124. _titleLabel.textAlignment = NSTextAlignmentCenter;
  125. _titleLabel.numberOfLines = 2;
  126. }
  127. return _titleLabel;
  128. }
  129. -(UIButton *)cancelButton {
  130. if (_cancelButton == nil) {
  131. _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
  132. _cancelButton.tag = 1;
  133. [_cancelButton setTitleColor:UIColorFromRGB(0xff6362) forState:UIControlStateNormal];
  134. [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
  135. [_cancelButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
  136. }
  137. return _cancelButton;
  138. }
  139. -(UIButton *)confirmButton {
  140. if (_confirmButton == nil) {
  141. _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
  142. _confirmButton.tag = 0;
  143. [_confirmButton setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal];
  144. [_confirmButton.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
  145. [_confirmButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
  146. }
  147. return _confirmButton;
  148. }
  149. -(UIView *)divideViewH {
  150. if (_divideViewH == nil) {
  151. _divideViewH = [[UIView alloc] init];
  152. _divideViewH.backgroundColor = UIColorFromRGB(0xe5e5e5);
  153. }
  154. return _divideViewH;
  155. }
  156. -(UIView *)divideViewV {
  157. if (_divideViewV == nil) {
  158. _divideViewV = [[UIView alloc] init];
  159. _divideViewV.backgroundColor = UIColorFromRGB(0xe5e5e5);
  160. }
  161. return _divideViewV;
  162. }
  163. @end