gpt4 book ai didi

iOS 增加 UIWebView 字体大小

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:16:10 24 4
gpt4 key购买 nike

我在 Stack Overflow 上寻找解决方案,但没有找到。我的代码是:

CGRect  rect = _postContentView.bounds;
_postContentUIWV = [[UIWebView alloc] initWithFrame:rect];
[_postContentUIWV loadHTMLString:selectedPostCD.content baseURL:nil];

int fontSize = 30;
NSString *jsString = [[NSString alloc] initWithFormat:
@"document.getElementsByTagName('span')[0].style.webkitTextSizeAdjust='%d%%'",
fontSize];
[_postContentUIWV stringByEvaluatingJavaScriptFromString:jsString];

[_postContentView addSubview:_postContentUIWV];

以及 UIWebView 中的 HTML 部分:

<p style="text-align: justify;">
<span style="line-height: 1.5em;">blablablablablabla</span>
</p>

我的代码不会增加 UIWebView 中的字体大小。我该如何解决?

最佳答案

_postContentUIWV的创建和初始化相关的代码留在viewDidLoad方法中:

- (void)viewDidLoad
{
[super viewDidLoad];

CGRect rect = _postContentView.bounds;
_postContentUIWV = [[UIWebView alloc] initWithFrame:rect];
_postContentUIWV.delegate = self;
[_postContentUIWV loadHTMLString:selectedPostCD.content baseURL:nil];
[_postContentView addSubview:_postContentUIWV];
}

jsString求值相关的代码移到webViewDidFinishLoad方法中:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
int fontSize = 30;
NSString *jsString = [[NSString alloc] initWithFormat:
@"document.getElementsByTagName('span')[0].style.webkitTextSizeAdjust='%d%%'",
fontSize];
[_postContentUIWV stringByEvaluatingJavaScriptFromString:jsString];
}

关于iOS 增加 UIWebView 字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23222850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com