NoticeViewController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // NoticeViewController.m
  3. // XenonSDK
  4. //
  5. // Created by SAGESSE on 2019/5/30.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "XenonSDK.h"
  9. #import "NoticeViewController.h"
  10. #import <objc/message.h>
  11. @interface NoticeViewController ()
  12. @property (nonatomic, strong) NSMutableArray* actions;
  13. @end
  14. @implementation NoticeViewController
  15. @synthesize title = _title;
  16. - (void)addActionWithName:(NSString*)name handler:(void(^)(void))handler {
  17. if (self.actions == nil) {
  18. self.actions = [[NSMutableArray alloc] init];
  19. }
  20. [self.actions addObject:[NSArray arrayWithObjects:name, (id)(handler), nil]];
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. if (self.title != nil) {
  25. self.titleLabel.text = self.title;
  26. }
  27. if ([self.contents isKindOfClass:NSString.self]) {
  28. CGRect rect = UIEdgeInsetsInsetRect(self.containerView.bounds, UIEdgeInsetsMake(0, 20, 0, 20));
  29. UILabel* label = [[UILabel alloc] initWithFrame:rect];
  30. NSMutableParagraphStyle* paragraph = [[NSMutableParagraphStyle alloc] init];
  31. NSMutableAttributedString* text = [[NSMutableAttributedString alloc] initWithString:self.contents];
  32. paragraph.lineSpacing = 4;
  33. [text addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, text.length)];
  34. label.attributedText = text;
  35. label.numberOfLines = 0;
  36. label.font = [UIFont systemFontOfSize:16];
  37. label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  38. [self.containerView addSubview:label];
  39. }
  40. if ([self.contents isKindOfClass:NSURL.self]) {
  41. CGFloat height = self.confirmButton.frame.size.height;
  42. CGRect frame = UIEdgeInsetsInsetRect(self.view.bounds, UIEdgeInsetsMake(0, 0, height, 0));
  43. // -[UIWebView initWithFrame:]
  44. UIView* webView = [[NSClassFromString(fqsd(@"iB0AAM3C0eDe0+fk9wA=")) alloc] initWithFrame:frame];
  45. if (webView == nil) {
  46. return;
  47. }
  48. webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  49. webView.backgroundColor = UIColor.clearColor;
  50. [self.view addSubview:webView];
  51. self.containerView.hidden = YES;
  52. self.titleLabel.hidden = YES;
  53. // -[UIWebView loadRequest:]
  54. ((void(*)(id,SEL,id))objc_msgSend)(webView, NSSelectorFromString(fqsd(@"rEsAAMHQ0pnAxLe7qr7L0AI=")), [NSURLRequest requestWithURL:self.contents]);
  55. }
  56. if (self.actions.count == 2) {
  57. [self.confirmButton setTitle:[self.actions[0] firstObject] forState:UIControlStateNormal];
  58. [self.confirmButton addTarget:self action:@selector(f1) forControlEvents:UIControlEventTouchUpInside];
  59. [self.cancelButton setTitle:[self.actions[1] firstObject] forState:UIControlStateNormal];
  60. [self.cancelButton addTarget:self action:@selector(f2) forControlEvents:UIControlEventTouchUpInside];
  61. }
  62. if (self.actions.count == 1) {
  63. UIView* superview = self.confirmButton.superview;
  64. [self.cancelButton removeFromSuperview];
  65. [self.confirmButton removeFromSuperview];
  66. [self.confirmButton setTitle:[self.actions[0] firstObject] forState:UIControlStateNormal];
  67. [self.confirmButton addTarget:self action:@selector(f1) forControlEvents:UIControlEventTouchUpInside];
  68. self.confirmButton.frame = superview.bounds;
  69. self.confirmButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  70. self.confirmButton.translatesAutoresizingMaskIntoConstraints = YES;
  71. [superview addSubview:self.confirmButton];
  72. [self.spaceLine removeFromSuperview]; }
  73. }
  74. - (void)f1 {
  75. if (self.actions.count >= 1) {
  76. void(^block)(void) = [self.actions[0] lastObject];
  77. if (block != nil) {
  78. block();
  79. }
  80. }
  81. }
  82. - (void)f2 {
  83. if (self.actions.count >= 2) {
  84. void(^block)(void) = [self.actions[1] lastObject];
  85. if (block != nil) {
  86. block();
  87. }
  88. }
  89. }
  90. @end