| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // WentingLicenseWebView.m
- // Unity-iPhone
- //
- // Created by 吴博 on 2021/7/23.
- //
- #import "WentingLicenseWebView.h"
- #import <WebKit/WKWebView.h>
- @interface WentingLicenseWebView()
- @property (nonatomic, strong)WKWebView *webView;
- @property (nonatomic, copy)NSString *url;
- @end
- @implementation WentingLicenseWebView
- - (id)initWithUrl:(NSString *)url {
- _url = url;
- return [super init];
- }
- - (void)loadUrl:(NSString *)url {
- _url = url;
- if (!_webView) return;
- [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
- }
- - (void)dealloc {
- if (_webView) {
- [_webView removeFromSuperview];
- _webView = nil;
- }
- }
- - (BOOL)prefersStatusBarHidden {
- return YES;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- if (@available(iOS 13.0, *)) {
- self.modalInPresentation = true;
- }
-
- CGRect frame = self.view.frame;
- self.view.backgroundColor = [UIColor whiteColor];
-
- UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
- if (@available(iOS 11.0, tvOS 11.0, *)) {
- insets = [self.view safeAreaInsets];
- }
- frame.origin.x += insets.left;
- frame.origin.y += insets.bottom; // Unity uses bottom left as the origin
- frame.size.width -= insets.left + insets.right;
- frame.size.height -= insets.top + insets.bottom;
-
- _webView = [[WKWebView alloc] init];
- _webView.frame = frame;
- [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
- [self.view addSubview:_webView];
-
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- button.backgroundColor = [UIColor greenColor];
- button.frame = CGRectMake((frame.origin.x + frame.size.width - 70), (frame.origin.y + frame.size.height - 40), 50, 20);
- button.titleLabel.font = [UIFont systemFontOfSize:14];
- [button setTitle:@"返回" forState:UIControlStateNormal];
- [button setTitleColor:[UIColor colorWithRed:104 green:221 blue:228 alpha:255] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(backBtnSel:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:button];
- }
- - (void)backBtnSel:(UIButton *)button {
- [self dismissViewControllerAnimated:NO completion:nil];
- }
- @end
|