2014-11-03 35 views
0

我有一個UIWebView,但不希望在頁面頂部顯示任何內容,最多可達50個像素。我需要一種裁剪UIWebView的方法,以便用戶無法看到高於50像素邊距的內容。我怎樣纔能有效地做到這一點?在Xcode中裁剪一個UIWebView

+1

只需簡單地用白色或黑色的背景色圖在網頁視圖的頂部,並給予其高度爲50 – 2014-11-03 06:59:56

+0

但是當用戶拖動到下面,他可以看到 – preetam 2014-11-03 07:00:45

+0

他只能看到直到他拖動,當他釋放拖動時它將不可見 – 2014-11-03 07:13:41

回答

2

UIWebview包含一個用於顯示HTML內容的UIScrollView。更改conent offfset允許更改頁面視圖...見例如谷歌

/** 
* basic webview boilerpoint 
*/ 
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 
                   0, 
                   CGRectGetWidth(self.view.frame), 
                   CGRectGetHeight(self.view.frame))]; 
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.co.uk"]]]; 
[self.view addSubview:webView]; 

/** 
* disable bounces so users cannot scroll beyond content & set top offset by 100 to hide parts of website 
*/ 
webView.scrollView.bounces = NO; 
webView.scrollView.contentInset = UIEdgeInsetsMake(-100, 0, 0, 0);