NEW: Learn iOS 11 with my latest book! >>

How to stop users selecting text in a UIWebView or WKWebView

Available from iOS 2.0

Using a web view to show rich media easily is a common thing to do, but by default users can select the text and that makes it look a little less like native code. To fix this, add the following CSS to the HTML you load, and users won't be able to select anything again:

<style type="text/css">
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}
</style>

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Want to build macOS apps?

Hacking with macOS delivers 18 awesome projects that teach you macOS development in no time – take control of your desktop today!

Click here to visit the Hacking with Swift store >>