Açıklama Yok

FKUpdateTipView.m 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // FKUpdateTipView.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/4/11.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKUpdateTipView.h"
  9. #import "FKWindowViewManager.h"
  10. @interface FKUpdateTipView ()
  11. @property (nonatomic, strong) UIImageView *bgImageView;
  12. @property (nonatomic, strong) UILabel *contentLabel;
  13. @property (nonatomic, strong) UIButton *confirmButton;
  14. @property (nonatomic, strong) UIButton *cancelButton;
  15. @property (nonatomic, strong) NSString *appUpdateURL;
  16. @end
  17. @implementation FKUpdateTipView
  18. /*
  19. // Only override drawRect: if you perform custom drawing.
  20. // An empty implementation adversely affects performance during animation.
  21. - (void)drawRect:(CGRect)rect {
  22. // Drawing code
  23. }
  24. */
  25. - (instancetype)init {
  26. self = [super init];
  27. if (self) {
  28. self.backgroundColor = [UIColor whiteColor];
  29. self.layer.cornerRadius = 8;
  30. }
  31. return self;
  32. }
  33. - (void)configViewWith:(FKUpdateType)type appUpdateURL:(NSString *)appUpdateURL content:(NSString *)content confirmTitle:(NSString *)confirmTitle cancelTitle:(NSString *)cancelTitle {
  34. [self addSubview:self.bgImageView];
  35. [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.centerX.equalTo(self);
  37. make.top.equalTo(self).offset(35);
  38. }];
  39. self.contentLabel.text = content;
  40. [self addSubview:self.contentLabel];
  41. [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.centerX.equalTo(self);
  43. make.top.equalTo(self.bgImageView.mas_bottom).offset(16);
  44. make.width.mas_equalTo(160);
  45. }];
  46. if (type == FKUpdateTypeAdvise) {
  47. // cancel
  48. [self.cancelButton setTitle:cancelTitle forState:UIControlStateNormal];
  49. [self addSubview:self.cancelButton];
  50. [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.centerX.equalTo(self);
  52. make.bottom.equalTo(self).offset(-32);
  53. make.size.mas_equalTo(CGSizeMake(160, 26));
  54. }];
  55. // confirm
  56. [self.confirmButton setTitle:confirmTitle forState:UIControlStateNormal];
  57. [self addSubview:self.confirmButton];
  58. [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.centerX.equalTo(self);
  60. make.bottom.equalTo(self).offset(-74);
  61. make.size.mas_equalTo(CGSizeMake(160, 26));
  62. }];
  63. } else {
  64. // confirm
  65. [self.confirmButton setTitle:confirmTitle forState:UIControlStateNormal];
  66. [self addSubview:self.confirmButton];
  67. [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.centerX.equalTo(self);
  69. make.bottom.equalTo(self).offset(-48);
  70. make.size.mas_equalTo(CGSizeMake(160, 26));
  71. }];
  72. }
  73. self.appUpdateURL = appUpdateURL;
  74. }
  75. + (CGFloat)heightWith:(FKUpdateType)type
  76. content:(NSString *)content {
  77. if (content) {
  78. CGSize size = [FLStringHelper rectOfString:content
  79. font:[UIFont systemFontOfSize:14]
  80. width:160].size;
  81. CGFloat height = 0;
  82. if (type == FKUpdateTypeAdvise) {
  83. height = (135 + size.height + 128);
  84. }
  85. if (type == FKUpdateTypeForce) {
  86. height = (135 + size.height + 90);
  87. }
  88. return MAX(280, height);
  89. }
  90. return 100;
  91. }
  92. #pragma mark - Action
  93. - (IBAction)clickConfirmButton:(id)sender {
  94. if (self.appUpdateURL.length > 0) {
  95. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.appUpdateURL]];
  96. }
  97. }
  98. - (IBAction)clickCancelButton:(id)sender {
  99. [[FKWindowViewManager sharedManager] closeFloatView];
  100. }
  101. #pragma mark - Property
  102. - (UIImageView *)bgImageView {
  103. if (!_bgImageView) {
  104. _bgImageView = [[UIImageView alloc] init];
  105. _bgImageView.image = [UIImage imageNamed:@"UpdateTipIcon"];
  106. }
  107. return _bgImageView;
  108. }
  109. - (UILabel *)contentLabel {
  110. if (!_contentLabel) {
  111. _contentLabel = [[UILabel alloc] init];
  112. _contentLabel.textColor = UIColorFromRGB(0x333333);
  113. _contentLabel.textAlignment = NSTextAlignmentCenter;
  114. _contentLabel.numberOfLines = 0;
  115. _contentLabel.font = [UIFont systemFontOfSize:14];
  116. }
  117. return _contentLabel;
  118. }
  119. - (UIButton *)confirmButton {
  120. if (!_confirmButton) {
  121. _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
  122. _confirmButton.backgroundColor = UIColorFromRGB(0xff6362);
  123. _confirmButton.layer.cornerRadius = 13;
  124. [_confirmButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
  125. [_confirmButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  126. [_confirmButton addTarget:self action:@selector(clickConfirmButton:) forControlEvents:UIControlEventTouchUpInside];
  127. }
  128. return _confirmButton;
  129. }
  130. - (UIButton *)cancelButton {
  131. if (!_cancelButton) {
  132. _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
  133. _cancelButton.backgroundColor = UIColorFromRGB(0xeeeeee);
  134. _cancelButton.layer.cornerRadius = 13;
  135. [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
  136. [_cancelButton setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal];
  137. [_cancelButton addTarget:self action:@selector(clickCancelButton:) forControlEvents:UIControlEventTouchUpInside];
  138. }
  139. return _cancelButton;
  140. }
  141. @end