webview剪辑在ios7上 [英] webview clipped on ios7

查看:134
本文介绍了webview剪辑在ios7上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

![在此处输入图像说明] [1]![在此输入图像说明] [2] Hy,我开发了一个阅读器,在使用.css添加水平分页后,在webview上显示html文件的内容。
一切都运行正常但是在ios7上我注意到webview在左边缘被剪辑了
我尝试了以下内容:

![enter image description here][1]![enter image description here][2]Hy, I have developed a reader that shows on a webview the content of an html file after adding horizontal paging to it using .css. Everything was working fine but on ios7 I have noticed that the webview is getting clipped at the left edge I have tried the following:

readingWebView.frame = CGRectMake(0, 0, 768, 920);   
[readingWebView loadHTMLString:loadString baseURL:nil];
readingWebView.autoresizingMask = UIViewAutoresizingFlexibleHeight |        UIViewAutoresizingFlexibleWidth;
readingWebView.clipsToBounds = false;
self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets = NO;

这是我的css文件:

html {
height:820px;
//margin:0px;
font-size:24px;
width:628px;
}

body {
margin:0px;
    padding:0px;
    width:628px;

}

#viewer {
    width:628px;
    height:820px;

}

#book {
width:628px;
height:820px;

margin-left:50px;
margin-right:50px;
//margin-top:100px;

-webkit-column-count:auto;
-webkit-column-width:668px;
-webkit-column-gap:140px;
text-align:justify;

 }

.h {
margin-top:8px;
 }


推荐答案

我认为这是一个CSS问题。显然webkit有一些不同的文本剪辑问题,可以通过在任何文本行的末尾添加& nbsp; 来解决。剪切一个单词后直接。

I think this is a CSS issue. Apparently webkit has a few different text clipping issues that can be solved just by adding   at the end of any text line. Directly after a word has been clipped.

您可以尝试修改一个html文件以添加& nbsp; 剪辑后的字母,看看它是否修复了?如果是这样,我们可以继续编写javascript,自动在正确的位置插入& nbsp;

Could you try modifying one of your html files to add   after the letters being clipped and see if it fixes it? If so we can pursue writing javascript that automatically inserts   at the correct places!

编辑:如果确实有效,请使用此javascript代码:

edit: If it does work use this javascript code:

var bodyText = "هذا هو بلدي النص الأساسي.";
var newBodyText = bodyText.replace(" ","  ");

第二个想法,因为你是一个RTL字符串,你可能需要使用它,不知道如何 string.replace 函数处理RTL

On second thought, since you are an RTL string you might need to use this instead, not sure how string.replace function handles RTL

var bodyText = "هذا هو بلدي النص الأساسي.";
var newBodyText = bodyText.replace(" ","  ");






编辑编辑:


edit edit:

要通过RegEx执行此操作(忽略HTML< *>脚本标记,在Objective-C中我相信您会使用此代码(我对RegEx知之甚少,所以如果它不起作用我只想用RegEx标签打开一个关于如何做到这一点的新问题,他们可能会在几分钟内得到答案!))。

To do this via RegEx (ignoring HTML <*>script tags, in Objective-C I believe you would use this code (I don't know much about RegEx so if it didn't work I would just open a new question with the RegEx tag about how to do this, they can probably get you an answer within minutes!)).

NSString *string = originalHTMLString;

NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?i)(<script(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</script\\s*>|<style(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</style\\s*>|<textarea(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</textarea\\s*>|</?[a-z](?:[^>\"']|\"[^\"]*\"]|'[^']*')*>|\\S+)|\\s+" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@"&nbsp; "];

finalHTMLString = modifiedString;

...再次,第二个想法,因为它是一种RTL语言,你实际上可能会使用这种变体将空间(从左到右)放入空间的代码:

... Again, on second thought, since it's an RTL language you may actually use this variation of the code which puts the nbsp AFTER (left to right) the space:

NSString *string = originalHTMLString;

NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?i)(<script(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</script\\s*>|<style(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</style\\s*>|<textarea(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</textarea\\s*>|</?[a-z](?:[^>\"']|\"[^\"]*\"]|'[^']*')*>|\\S+)|\\s+" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@" &nbsp;"];

finalHTMLString = modifiedString;

这篇关于webview剪辑在ios7上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆