我有一个加载html5横幅的UIView。由于横幅宽度比UIWebView短,因此在横幅的每一侧都会有填充。然而..每边的填充比我应该得到的要大得多。使用填充来居中UIWebView内容
我只是想横幅中心,如果横幅比UIWebView短。
而不是寻找这样的:(其中X为旗帜和O是填充)
| OOXXXXXXOO |
它看起来像这样:
| OOOOXXXXXX |
在这里,如果我启用滚动,我可以居中它像第一个例子。
我该如何解决这个问题?
代码
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:bannerIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"bannerCell"];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.bounds.size.width, cell.contentView.bounds.size.height)];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
webView.userInteractionEnabled = YES;
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
webView.delegate = self;
webView.scrollView.bounces = NO;
webView.scrollView.scrollEnabled = NO;
webView.scalesPageToFit = YES;
NSURL *url = [NSURL URLWithString:@"http://example.com/page.html"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[cell.contentView addSubview:webView];
}
您最好的选择是设计网页,以更加灵活。你是否使用横幅容器的固定宽度? – Jeremy 2013-04-24 13:39:48