NEW: How to update your app design for iPhone X >>

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.

Take Swift further!

Your Swift skills let you make apps for macOS, watchOS, tvOS, and more, and for one low price you can learn it all with my Swift Platform Pack!

Click here to visit the Hacking with Swift store >>