在我的应用中
我使用html生成报告并在UIWebView中显示它。
我正在使用Html表格式化webview中的数据。
附上一些屏幕截图以便更好地理解:
如第二个屏幕的第一轮标记所示,表格对齐错位。
我用于生成此表的代码如下。
[html appendFormat:@"<h3 style =\"font-family: Arial\">Expressive <h3><br/>"];
NSString *htmlString1= @"<table border=\"1\" style=\"width: 100%; border: 1px #000 solid; border-collapse: collapse; font-size: 13px; font-family: sans-serif;\">";
for (int i=0; i<2; i++) //Two Rows
{
htmlString1 = [htmlString1 stringByAppendingString:@"<tr>"];
for (int j=0; j<2; j++) //Two Columns
{
if (i==0)
{
if(j==0)
{
htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<th style=\"text-align:center;font-size:16;width:30;height:20\"><b>Correct-%.00f%%</b></th>",correctPercent]];
}
else if(j==1)
{
htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<th style=\"text-align:center;font-size:16;width:30;height:20\"><b>Incorrect-%.00f%%</b></th>",incorrectPercent]];
}
}
else
{
if(j==0)
{
NSString *val = @"";
if([[[newArray valueForKey:@"Expressive"]valueForKey:@"CorrectResults"] count]>0)
{
val = [[[newArray valueForKey:@"Expressive"]valueForKey:@"CorrectResults"] componentsJoinedByString:@"<br/>"];
}
htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<td style=\"text-align:center;width:40%;height:50;\">%@</td>",val]]; //E
}
else if(j==1)
{
NSString *val = @"";
if([[[newArray valueForKey:@"Expressive"] valueForKey:@"InCorrectResults"] count]>0)
{
val = [[[newArray valueForKey:@"Expressive"]valueForKey:@"InCorrectResults"] componentsJoinedByString:@"<br/>"];
}
htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<td style=\"text-align:center;width:40%;height:50;\">%@</td>",val]];
}
}
}
htmlString1 = [htmlString1 stringByAppendingString:@"</tr>"];
}
htmlString1 = [htmlString1 stringByAppendingString:@"</table>"];
[html appendString:htmlString1];
[html appendString:@"<br/>"];
如何解决这个问题?
答案 0 :(得分:0)
使用px
或%
指定列的宽度:
htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<th style=\"text-align:center;font-size:16;width:30%;height:20px\"><b>Correct-%.00f%%</b></th>",correctPercent]];
等...