NEW: Check out my incredible new SpriteKit book! >>

How to stop users selecting text in a UIWebView or WKWebView

Written by Paul Hudson    @twostraws

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>

Available from iOS 2.0

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.

Swift on the server is here

Get ahead of the game and learn server-side Swift with my latest book – build real-world projects while you learn!

Click here to visit the Hacking with Swift store >>