EveryDayFirstLoginPopView.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // EveryDayFirstLoginPopView.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/11/30.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "EveryDayFirstLoginPopView.h"
  9. @interface EveryDayFirstLoginPopView ()
  10. //@property(nonatomic, strong) UIView *bgView;
  11. //@property(nonatomic, strong) UIButton *tipButton;
  12. @property(nonatomic, strong) UIImageView *bgImageView;
  13. @property(nonatomic, strong) UIImageView *titleImageView;
  14. @property(nonatomic, strong) UILabel *scoreLabel;
  15. @property(nonatomic, strong) UIButton *closeButton;
  16. @property(nonatomic, strong) NSString *score;
  17. @property(nonatomic, strong) dismissBlock block;
  18. @end
  19. static NSString *const image_name_bg = @"首次弹窗背景";
  20. static NSString *const image_name_success = @"每日首次登录奖励";
  21. static NSString *const image_name_btn = @"知道了按钮";
  22. @implementation EveryDayFirstLoginPopView
  23. +(void)showEveryDayFirstLoginViewScore:(NSString *)score WithComplete:(dismissBlock)complete{
  24. EveryDayFirstLoginPopView *view=[[EveryDayFirstLoginPopView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  25. view.score = score;
  26. view.block = complete;
  27. [view pop];
  28. }
  29. - (void)setScore:(NSString *)score{
  30. _score = score;
  31. // _scoreLabel.text = [NSString stringWithFormat:ASLocalizedString(@"+%@经验"),score];
  32. NSString * str = [NSString stringWithFormat:ASLocalizedString(@"+%@经验"),score];
  33. NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc]initWithString:str];
  34. [attribute setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} range:NSMakeRange(str.length-2, 2)];
  35. [_scoreLabel setAttributedText:attribute];
  36. }
  37. - (instancetype)initWithFrame:(CGRect)frame {
  38. self = [super initWithFrame:frame];
  39. if (self) {
  40. [self initUI];
  41. }
  42. return self;
  43. }
  44. - (void)initUI {
  45. // self.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.4];
  46. _bgImageView = ({
  47. UIImageView * iv = [[UIImageView alloc] init];
  48. iv.image = [UIImage imageNamed:image_name_bg];
  49. iv.userInteractionEnabled = YES;
  50. iv;
  51. });
  52. _titleImageView = ({
  53. UIImageView * iv = [[UIImageView alloc] init];
  54. iv.image = [UIImage imageNamed:image_name_success];
  55. iv;
  56. });
  57. _scoreLabel = ({
  58. UILabel * label = [[UILabel alloc]init];
  59. label.textColor = [UIColor colorWithHexString:@"#9D21FE"];
  60. label.font = [UIFont boldSystemFontOfSize:36];
  61. label.text = @"";
  62. label;
  63. });
  64. _closeButton = ({
  65. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  66. [btn setBackgroundImage:[UIImage imageNamed:image_name_btn] forState:UIControlStateNormal];
  67. [btn setTitle:ASLocalizedString(@"我知道了")forState:UIControlStateNormal];
  68. [btn setTitleColor:[UIColor colorWithHexString:@"#CD49FF"] forState:UIControlStateNormal];
  69. btn.titleLabel.font = [UIFont systemFontOfSize:18];
  70. [btn addTarget:self action:@selector(dismissAction) forControlEvents:UIControlEventTouchUpInside];
  71. btn;
  72. });
  73. [self addSubview:_bgImageView];
  74. [_bgImageView addSubview:_titleImageView];
  75. [_bgImageView addSubview:_scoreLabel];
  76. [_bgImageView addSubview:_closeButton];
  77. }
  78. - (void)dismissAction{
  79. [self dismiss];
  80. !self.block?:self.block();
  81. }
  82. - (void)layoutSubviews {
  83. [super layoutSubviews];
  84. [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  85. // make.top.mas_equalTo(190);
  86. make.centerX.mas_equalTo(0);
  87. make.centerY.mas_equalTo(0);
  88. }];
  89. [_titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.top.mas_equalTo(24);
  91. make.centerX.mas_equalTo(0);
  92. }];
  93. [_scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.top.equalTo(_titleImageView.mas_bottom).offset(14);
  95. make.centerX.mas_equalTo(0);
  96. }];
  97. [_closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.bottom.mas_equalTo(-20);
  99. make.centerX.mas_equalTo(0);
  100. }];
  101. }
  102. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  103. UITouch *touch = [touches anyObject];
  104. if ([touch.view isEqual:self]) {
  105. [self dismiss];
  106. }
  107. }
  108. -(void)pop
  109. {
  110. UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
  111. [keyWindow addSubview:self];
  112. self.bgImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  113. [UIView animateWithDuration:0.3 animations:^{
  114. self.bgImageView.transform = CGAffineTransformIdentity;
  115. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  116. }];
  117. }
  118. -(void)dismiss
  119. {
  120. [UIView animateWithDuration:0.3 animations:^{
  121. self.bgImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  122. } completion:^(BOOL finished) {
  123. [self removeFromSuperview];
  124. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
  125. }];
  126. }
  127. @end