webview_content

2022-03-30  本文已影响0人  管饱饱

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

<title>${webview_title}</title>

<link type="text/css" rel="stylesheet" href="../css/common.css">

<link type="text/css" rel="stylesheet" href="../css/facetimu.css">

        <style type="text/css">

            .article-content p, .article-content span{

                font-size:18px;

                line-height:36px;

                color:#333;

                background-color:#f8f8f8;

            }

        .article-pagelet ,body{

            background-color:#f8f8f8;

        }

        .article-content img{

            max-width:100%;height:auto;

        }

        .img-parent {

            text-align:center;

            margin-bottom:10px;

        }

        </style>

</head>

<body>

<article id="article-pagelet">

<div class="article-detail">

<div class="article-content">

${webview_content}

</article>

</body>

</html>

#import

@interface WebContentManager : NSObject

+ (instancetype)sharedManager;

+ (NSString *)faceTimuPatternedWithContentAndNoHead:(NSString *)timu;

@end

path = [[NSBundle mainBundle] pathForResource:@"facetimu" ofType:@"html"];

        shared_manager.facetimu_htmlStr = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];

        if(error) {

            DebugLog(@"facetimu_htmlStr fail: %@", error.description);

        }

#import "WebContentManager.h"

@interface WebContentManager ()

@property (strong, nonatomic) NSString *facetimu_htmlStr;

@end

@implementation WebContentManager

+ (instancetype)sharedManager {

    staticWebContentManager*shared_manager =nil;

    static dispatch_once_t pred;

    dispatch_once(&pred, ^{

        shared_manager = [[selfalloc]init];

        NSString *path = [[NSBundle mainBundle] pathForResource:@"bubble" ofType:@"html"];

        NSError*error =nil;

        //面试题目

        path = [[NSBundle mainBundle] pathForResource:@"facetimu" ofType:@"html"];

        shared_manager.facetimu_htmlStr = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];

        if(error) {

            DebugLog(@"facetimu_htmlStr fail: %@", error.description);

        }

    });

    returnshared_manager;

}

//面试题目

- (NSString *)faceTimuPatternedWithContent:(NSString *)timu{

    timu = [NSString stringWithFormat:@"%@%@",timu,@"<br>"];

    NSString*patternedStr =self.facetimu_htmlStr;

    patternedStr = [patternedStrstringByReplacingOccurrencesOfString:@"${webview_content}" withString:timu];

    returnpatternedStr;

}

//面试题目2 跟上面的区别是把\n转成换行了

- (NSString *)faceTimu2PatternedWithContent:(NSString *)timu{

    timu = [timustringByReplacingOccurrencesOfString:@"\r" withString:@"\n"];

    timu = [selfdeleteMoreN:timu];

//    timu = [timu stringByReplacingOccurrencesOfString:@"\n" withString:@""];

//    timu = [timu stringByReplacingOccurrencesOfString:@"\\s{1}" withString:@"\n"];

//    timu = [timu stringByReplacingOccurrencesOfString:@"\n\n" withString:@"\n"];

    timu = [timustringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];

    timu = [NSString stringWithFormat:@"%@%@",timu,@"<br>"];

    NSString*patternedStr =self.facetimu1_htmlStr;

    patternedStr = [patternedStrstringByReplacingOccurrencesOfString:@"${webview_content}" withString:timu];

    returnpatternedStr;

}

- (NSString*)deleteMoreN:(NSString*)timu{

    NSString*newTimu =@"";

    NSArray *arr = [timu componentsSeparatedByString:@"\n"];

    BOOLisNew =NO;

    for(NSString*iteminarr) {

        if([itemisEqualToString:@""]) {

            if(!isNew) {

                newTimu = [newTimustringByAppendingString:@"\n"];

                isNew =YES;

            }

            else{

            }

        }

        else{

            isNew =NO;

            newTimu = [newTimustringByAppendingString:item];

        }

    }

    returnnewTimu;

}

+ (NSString *)faceTimuPatternedWithContentAndNoHead:(NSString *)timu{

    return [[self sharedManager] faceTimuPatternedWithContent:timu];

}

@end

[_timuWebView loadHTMLString:[WebContentManager faceTimuPatternedWithContentAndNoHead:detailModel.ask] baseURL:nil];

            _timuWebView.UIDelegate=self;

            _timuWebView.navigationDelegate=self;

上一篇下一篇

猜你喜欢

热点阅读