KSUpdateAlert.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // KSUpdateAlert.m
  3. // TeacherDaya
  4. //
  5. // Created by Kyle on 2021/5/13.
  6. // Copyright © 2021 DayaMusic. All rights reserved.
  7. //
  8. #import "KSUpdateAlert.h"
  9. #import <KSToolLibrary/UIView+Animation.h>
  10. @interface KSUpdateAlert ()
  11. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  12. @property (weak, nonatomic) IBOutlet UILabel *descLabel;
  13. @property (weak, nonatomic) IBOutlet UIView *noforceView;
  14. @property (weak, nonatomic) IBOutlet UIView *forceView;
  15. @property (nonatomic, copy) UpdateCallback callback;
  16. @end
  17. @implementation KSUpdateAlert
  18. + (instancetype)shareInstance {
  19. KSUpdateAlert *view = [[[NSBundle mainBundle] loadNibNamed:@"KSUpdateAlert" owner:nil options:nil] firstObject];
  20. view.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
  21. return view;
  22. }
  23. - (void)configWithMemo:(NSString *)memo desc:(NSString *)descMessage isForce:(BOOL)isForce callback:(UpdateCallback)callback {
  24. if (callback) {
  25. self.callback = callback;
  26. }
  27. if (isForce) {
  28. self.forceView.hidden = NO;
  29. self.noforceView.hidden = YES;
  30. }
  31. else {
  32. self.forceView.hidden = YES;
  33. self.noforceView.hidden = NO;
  34. }
  35. self.tipsLabel.text = [NSString stringWithFormat:@"V%@新版本抢先体验",memo];
  36. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  37. [paragraphStyle setLineSpacing:4];//调整行间距
  38. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:descMessage attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f weight:UIFontWeightMedium],NSForegroundColorAttributeName:HexRGB(0x808080)}];
  39. self.descLabel.attributedText = attrStr;
  40. }
  41. - (void)showAlert {
  42. [[UIApplication sharedApplication].keyWindow addSubview:self];
  43. [self setPopAnimation];
  44. }
  45. - (void)hiddenAction {
  46. [self removeFromSuperview];
  47. }
  48. - (IBAction)cancleAction:(id)sender {
  49. if (self.callback) {
  50. self.callback(NO);
  51. }
  52. [self hiddenAction];
  53. }
  54. - (IBAction)sureAction:(id)sender {
  55. if (self.callback) {
  56. self.callback(YES);
  57. }
  58. [self hiddenAction];
  59. }
  60. /*
  61. // Only override drawRect: if you perform custom drawing.
  62. // An empty implementation adversely affects performance during animation.
  63. - (void)drawRect:(CGRect)rect {
  64. // Drawing code
  65. }
  66. */
  67. @end