[英]UIWebView increases font size if there's more text
您好,我試圖通過具有UIWebView子視圖的同一個UIViewController顯示兩個不同的html頁面。
兩個HTML頁面使用相同的CSS,並且結構相似。 但是,我注意到,在iOS Simulator和設備上查看時,內容較少的頁面的字體大小明顯小於內容較多的頁面的字體大小。
有人可以向我解釋在兩種視圖中都使用相同的字體大小該怎么辦?
這是我的UIWebView代碼:
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
self.webView = [[[UIWebView alloc] initWithFrame: appFrame] autorelease];
self.webView.backgroundColor= [UIColor whiteColor];
self.webView.scalesPageToFit= YES;
self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *filePath = [[NSBundle mainBundle] pathForResource:self.resourceName ofType:@"html"];
NSURL *urlLocation= [NSURL fileURLWithPath:filePath];
[self.webView loadRequest:[NSURLRequest requestWithURL:urlLocation]];
self.view = self.webView;
這是相關的html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4 /loose.dtd">
<html>
<head>
<LINK href="manual.css" rel="stylesheet" type="text/css">
<title>My Info text</title>
</head>
<body>
<table >
<tr>
<td class="title">
<b>How to do it</b>
</td>
</tr>
<tr>
<td class ="content">
Some Instructions on how to do it properly.
</td>
</tr>
</table>
</body>
</html>
這是CSS。 主要問題似乎是td.content,因為標題大小正確(或兩個屏幕之間至少沒有明顯不同):
body {
background-color : rgb(255,255,255);
font-size : 35px;
font-family : Helvetica;
color : rgb(54,54,54);
margin-right : 0px;
margin-left : 0px;
}
table {
width : 100%;
height: 100%;
margin-top : 20px;
margin-bottom : 20px;
margin-right : 0px;
margin-left : 0px;
border-spacing : 0px;
padding-right : 0px;
padding-left : 0px;
}
tr {
margin-top : 0px;
margin-bottom : 0px;
margin-right : 0px;
margin-left : 0px;
}
td.content {
font-size : 1em;
text-align : left;
vertical-align: top;
margin-top : 0px;
margin-bottom : 0px;
margin-right : 0px;
margin-left : 0px;
padding-top : 5px;
padding-bottom : 10px;
padding-right : 30px;
padding-left : 30px;
}
td.title {
width : 170px;
font-size : 1.5em;
font-weight : bold;
text-align : left;
vertical-align : top;
margin-top : 0px;
margin-bottom : 0px;
margin-right : 0px;
margin-left : 0px;
padding-top : 5px;
padding-bottom : 10px;
padding-right : 30px;
padding-left : 30px;
}
我有2個按鈕-A-和A +
@interface
NSUInteger textFontSize;
- (IBAction)changeTextFontSize:(id)sender
switch ([sender tag]) {
case 1: // A-
textFontSize = (textFontSize > 50) ? textFontSize -5 : textFontSize;
break;
case 2: // A+
textFontSize = (textFontSize < 160) ? textFontSize +5 : textFontSize;
break;
}
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",
textFontSize];
[web stringByEvaluatingJavaScriptFromString:jsString];
[jsString release];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.