webview_content

<!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 跟上面的區(qū)別是把\n轉(zhuǎ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;

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容