html5 バナーをロードする UIView があります。バナーの幅が 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];
}