博客> iOS-UIWeb相关
iOS-UIWeb相关
2018-10-21 04:37 评论:0 阅读:688 OS_JJ
ios UIWeb相关
- (void)loadView
{
    self.view = [[UIWebView alloc] init];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // 设置标题
    self.title = self.html.title;

    UIWebView *webView = (UIWebView *)self.view;
    webView.delegate = self;

    // 创建URL
    NSURL *url = [[NSBundle mainBundle] URLForResource:self.html.html withExtension:nil];

    // 创建请求
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    // 发送请求加载网页
    [webView loadRequest:request];

    /**
 *  网页加载完毕的时候调用
 */
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    // 跳到id对应的网页标签

    // 1.拼接Javacript代码
    NSString *js = [NSString stringWithFormat:@"[removed].href = '#%@';", self.html.ID];
    // 2.执行JavaScript代码
    [webView stringByEvaluatingJavaScriptFromString:js];
}
@end
收藏
0
sina weixin mail 回到顶部