2017-10-26 4 views
1

iOS 프로그래밍의 웹킷 콘텐츠와 관계없이 WKWebView의 글꼴 크기를 변경하는 방법은 무엇입니까? 내가wkwebview 글꼴 크기의 크기를 조정하는 방법은 무엇입니까?

[Webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"resizeText(%lu)",(unsigned long)fontSize]];을 사용하고 그러나 웹보기 글꼴 크기를 변경하지 않습니다

.

+0

당신이 웹보기에 htmlstring를로드하는 다음과 같이

fontCSS 방법은있는 NSString 범주에있어, 무엇입니까? – Kuldeep

+0

로드 중 URL [self.wkWebView loadRequest : [NSURLRequest requestWithURL : pageUrl]]; – Angel

답변

0

콘텐츠에 CSS 코드를 추가하는 것이 좋습니다.

나는이 한 번해야했다, 여기 내 코드의 예는 다음과 같습니다
NSString *systemFont = [[[UIFont systemFontOfSize:11.f] description] fontCSS]; 
NSString *boldFont = [[[UIFont boldSystemFontOfSize:12.f] description] fontCSS]; 
// The above fonts can be changed to your liking. 
NSString *oldContent = ___; // This is the html content that was loaded. 
NSString *content = [NSString stringWithFormat:@"<html><head>\ 
        <style>\ 
        img,iframe{max-width:100%%; width:auto; height:auto; display:block; margin-left:auto; margin-right:auto; margin-bottom:20px}\ 
        body{%@; margin-left:24px; margin-right:24px; margin-bottom:24px}\ 
        strong{%@}\ 
        </style>\ 
        </head><body>%@</body></html>", systemFont, boldFont, oldContent]; 

지금 당신은 당신의 webview으로 content 변수를 사용합니다.

-(NSString *)fontCSS 
{ 
    NSRange range = [self rangeOfString:@"font-family"]; 

    return [self substringFromIndex:range.location]; 
} 
+0

실제로 loadHTMLString이 아닌 url (loadrequest 메서드)을로드하고 있습니다. – Angel

관련 문제