1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- //
- // ASWebViewController.m
- // Asteria
- //
- // Created by iOS on 2023/6/24.
- //
- #import "ASWebViewController.h"
- @interface ASWebViewController ()<WKNavigationDelegate, WKUIDelegate>
- @property (nonatomic, strong) WKWebView *webView;
- @end
- @implementation ASWebViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadSubVs];
- [self configViews];
-
- [self beginLoad];
- }
- - (void)beginLoad {
- NSURL *url = [NSURL URLWithString:self.webUrl];
- if (!url) {
- return;
- }
- NSURLRequest *requst = [NSURLRequest requestWithURL:url];
- [self.webView loadRequest:requst];
- }
- - (void)configViews {
- [self setTitleStr:self.customTitle];
- [self setNavRightSearch:^{
-
- }];
-
- }
- - (void)loadSubVs {
- [self.view addSubview:self.webView ];
- [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.customNavBar.mas_bottom);
- make.bottom.leading.trailing.equalTo(self.view);
- }];
-
- }
- // MARK: - subvs
- - (WKWebView *)webView {
- if (!_webView) {
- WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- WKWebView *v = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
- v.navigationDelegate = self;
- v.UIDelegate = self;
- _webView = v;
- }
- return _webView;
- }
- // MARK: - uidelegate navidelegate
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
- [webView evaluateJavaScript:@"document.title" completionHandler:^(id _Nullable title, NSError * _Nullable error) {
- NSString *titleStr = [NSString stringWithFormat:@"%@",title];
- if (!titleStr.isEmpty) {
- [self setTitleStr:titleStr];
-
- }
-
- }];
- }
- @end
|