iOS
UIWebView
disable scroll
mobile development
webview customization

Disable Scroll on a UIWebView allowed?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Yes, disabling scroll on UIWebView is possible, even though UIWebView is deprecated. The key is that UIWebView embeds a UIScrollView, and scroll behavior is controlled there. If you maintain a legacy app, this pattern lets you lock content in place while you plan migration to WKWebView.

Disable Scrolling in UIWebView

A UIWebView instance exposes its internal scroll view as scrollView. Set scrolling flags after creating the view and before user interaction starts.

objective-c
1#import <UIKit/UIKit.h>
2
3@interface ViewController : UIViewController <UIWebViewDelegate>
4@property (nonatomic, strong) UIWebView *webView;
5@end
6
7@implementation ViewController
8
9- (void)viewDidLoad {
10    [super viewDidLoad];
11
12    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
13    self.webView.delegate = self;
14
15    self.webView.scrollView.scrollEnabled = NO;
16    self.webView.scrollView.bounces = NO;
17
18    [self.view addSubview:self.webView];
19
20    NSURL *url = [NSURL URLWithString:@"https://example.com"];
21    NSURLRequest *req = [NSURLRequest requestWithURL:url];
22    [self.webView loadRequest:req];
23}
24
25@end

In Swift, the same approach looks like this:

swift
1import UIKit
2
3final class ViewController: UIViewController {
4    private let webView = UIWebView()
5
6    override func viewDidLoad() {
7        super.viewDidLoad()
8
9        webView.frame = view.bounds
10        webView.scrollView.isScrollEnabled = false
11        webView.scrollView.bounces = false
12
13        view.addSubview(webView)
14
15        if let url = URL(string: "https://example.com") {
16            let request = URLRequest(url: url)
17            webView.loadRequest(request)
18        }
19    }
20}

These snippets are valid for legacy codebases still compiling with old SDK targets.

Control Zoom and Content Size Side Effects

Disabling scroll alone may not be enough. Web pages with wide content can still feel broken if zoom is active or the viewport is not configured.

If you control the HTML, include a viewport meta tag to keep scale predictable:

html
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

For local HTML content in Objective-C, inject this when needed:

objective-c
1NSString *html = @"<!doctype html><html><head>"
2                 "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">"
3                 "</head><body><p>Static content</p></body></html>";
4[self.webView loadHTMLString:html baseURL:nil];

This keeps layout stable when scrolling is disabled and avoids a confusing half-zoomed interface.

Keep Interaction Usable on Fixed Content

When scrolling is disabled, users still need reliable tap behavior for links and buttons inside the page. If page elements rely on drag gestures, fixed mode can make those interactions feel broken.

For app controlled content, use CSS to prevent accidental text selection and overscroll style effects:

html
1<style>
2  html, body {
3    overflow: hidden;
4    -webkit-user-select: none;
5    touch-action: manipulation;
6  }
7</style>

Then keep actionable controls large and tap friendly so users do not depend on scroll or zoom for precision.

Apply the Same Behavior in WKWebView

If you are migrating, implement equivalent behavior in WKWebView so UI behavior does not change during the transition.

swift
1import UIKit
2import WebKit
3
4final class WebScreen: UIViewController {
5    private let webView = WKWebView(frame: .zero)
6
7    override func viewDidLoad() {
8        super.viewDidLoad()
9
10        webView.frame = view.bounds
11        webView.scrollView.isScrollEnabled = false
12        webView.scrollView.bounces = false
13        webView.scrollView.pinchGestureRecognizer?.isEnabled = false
14
15        view.addSubview(webView)
16
17        if let url = URL(string: "https://example.com") {
18            webView.load(URLRequest(url: url))
19        }
20    }
21}

WKWebView has better performance, modern security behavior, and long term platform support. Keeping scroll settings mirrored reduces migration risk.

Common Pitfalls

A common issue is disabling scroll on the wrong object. You must configure webView.scrollView, not only the outer container view.

Another issue is setting properties too late, such as after layout transitions or after replacing the web view instance. Apply scroll settings immediately after creating the web view and reapply after recreation.

Legacy projects sometimes disable scrolling but leave bounce and pinch enabled. That creates a strange UI where the page appears locked yet still shifts or scales. Disable the related behaviors together when your screen requires fixed content.

Summary

  • Disabling scroll on UIWebView is supported through its internal UIScrollView.
  • Set scrollEnabled and bounces to lock content position in legacy screens.
  • Add viewport configuration to prevent zoom and sizing issues.
  • Preserve tap-friendly interaction when content is fixed in place.
  • Mirror the same behavior in WKWebView during migration.

Course illustration
Course illustration

All Rights Reserved.