123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- //
- // NoticeViewController.m
- // XenonSDK
- //
- // Created by SAGESSE on 2019/5/30.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "XenonSDK.h"
- #import "NoticeViewController.h"
- #import <objc/message.h>
- @interface NoticeViewController ()
- @property (nonatomic, strong) NSMutableArray* actions;
- @end
- @implementation NoticeViewController
- @synthesize title = _title;
- - (void)addActionWithName:(NSString*)name handler:(void(^)(void))handler {
- if (self.actions == nil) {
- self.actions = [[NSMutableArray alloc] init];
- }
- [self.actions addObject:[NSArray arrayWithObjects:name, (id)(handler), nil]];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- if (self.title != nil) {
- self.titleLabel.text = self.title;
- }
-
- if ([self.contents isKindOfClass:NSString.self]) {
- CGRect rect = UIEdgeInsetsInsetRect(self.containerView.bounds, UIEdgeInsetsMake(0, 20, 0, 20));
- UILabel* label = [[UILabel alloc] initWithFrame:rect];
-
- NSMutableParagraphStyle* paragraph = [[NSMutableParagraphStyle alloc] init];
- NSMutableAttributedString* text = [[NSMutableAttributedString alloc] initWithString:self.contents];
-
- paragraph.lineSpacing = 4;
- [text addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, text.length)];
-
- label.attributedText = text;
- label.numberOfLines = 0;
- label.font = [UIFont systemFontOfSize:16];
- label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-
- [self.containerView addSubview:label];
- }
- if ([self.contents isKindOfClass:NSURL.self]) {
-
- CGFloat height = self.confirmButton.frame.size.height;
- CGRect frame = UIEdgeInsetsInsetRect(self.view.bounds, UIEdgeInsetsMake(0, 0, height, 0));
-
- // -[UIWebView initWithFrame:]
- UIView* webView = [[NSClassFromString(fqsd(@"iB0AAM3C0eDe0+fk9wA=")) alloc] initWithFrame:frame];
- if (webView == nil) {
- return;
- }
- webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- webView.backgroundColor = UIColor.clearColor;
-
- [self.view addSubview:webView];
- self.containerView.hidden = YES;
- self.titleLabel.hidden = YES;
- // -[UIWebView loadRequest:]
- ((void(*)(id,SEL,id))objc_msgSend)(webView, NSSelectorFromString(fqsd(@"rEsAAMHQ0pnAxLe7qr7L0AI=")), [NSURLRequest requestWithURL:self.contents]);
- }
-
- if (self.actions.count == 2) {
-
-
- [self.confirmButton setTitle:[self.actions[0] firstObject] forState:UIControlStateNormal];
- [self.confirmButton addTarget:self action:@selector(f1) forControlEvents:UIControlEventTouchUpInside];
-
- [self.cancelButton setTitle:[self.actions[1] firstObject] forState:UIControlStateNormal];
- [self.cancelButton addTarget:self action:@selector(f2) forControlEvents:UIControlEventTouchUpInside];
- }
- if (self.actions.count == 1) {
-
- UIView* superview = self.confirmButton.superview;
-
- [self.cancelButton removeFromSuperview];
- [self.confirmButton removeFromSuperview];
-
- [self.confirmButton setTitle:[self.actions[0] firstObject] forState:UIControlStateNormal];
- [self.confirmButton addTarget:self action:@selector(f1) forControlEvents:UIControlEventTouchUpInside];
-
- self.confirmButton.frame = superview.bounds;
- self.confirmButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- self.confirmButton.translatesAutoresizingMaskIntoConstraints = YES;
-
- [superview addSubview:self.confirmButton];
-
- [self.spaceLine removeFromSuperview]; }
- }
- - (void)f1 {
- if (self.actions.count >= 1) {
- void(^block)(void) = [self.actions[0] lastObject];
- if (block != nil) {
- block();
- }
- }
- }
- - (void)f2 {
- if (self.actions.count >= 2) {
- void(^block)(void) = [self.actions[1] lastObject];
- if (block != nil) {
- block();
- }
- }
- }
- @end
|