I have the simplest view. A webview with some static HTML code embedded using the loadHTMLString
message. The only thing I've modifed in the webview's properties from the storyboard is the "Scale page to fit" property (it's checked). However, as you can see in the image below, there's an empty space above the HTML that belongs to the webview (if I scroll the content it fills up that space). I've even tried just using...
<html>
<body><h1>Hello</h1></body>
</html>
... but the space is still there (so I don't think it has anything to do with the HTML code).
How can I remove that space?
iOS adjusts the content inset only for the first view in the view hierarchy if it is UIScrollView or it's descendant (e.g.
UITableView
andUICollectionView
, in your case its aUIWebView
). If your view hierarchy includes multiple scroll views,automaticallyAdjustsScrollViewInsets
will make adjustments only to the first one.Here's how to change this behavior:
a) Interface Builder
Select the view controller Open Attributes inspector There's a property called "Adjust scroll view insets" in IB's attribute inspector (when a ViewController is selected) which is on by default.
b) Programmatically
Add this to i.e.
viewDidLoad
methodObj-C:
self.automaticallyAdjustsScrollViewInsets = NO;
Swift:
self.automaticallyAdjustsScrollViewInsets = false
Turn off adjusts scroll view insets.It's here: