I am working on an app that loads small chunks of HTML into several webviews. I want this HTML to be selectable by the user, so they can copy and paste portions of it. This is working totally fine, but only when the content is greater than 100px
tall. For some reason, if it is any shorter, the content can not be selected by the user.
Steps to reproduce:
loadHTMLString: "W " * 64, baseURL: nil
on the webview. (on my screen this is 4 complete rows of "W"s)loadHTMLString: "W " * 65, baseURL: nil
on the webview. (on my screen the last "W" is on the 5th row)I've tried a number of thing, to understand what is happening here. I you follow the same steps, but start with a height of 101 instead of 100, it works perfectly find with only 4 rows.
I think this might be a bug in iOS? Maybe?
I'm running iOS 9.2
, with Xcode 7.2.1
Does anyone here know why this might be happening, or if there is any sort of work around that I can use to fix this?
I've tried a few workarounds, to no avail.
The only workaround I've found: use WKWebView
-- it does not have this issue.
Currently, as of iOS 9, you cannot add WKWebView
through Interface Builder. This is because it is not supported. You won't be able to include it in IB, as long as WKWebView
header declares it as NS_UNAVAILABLE
:
- (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
Instead, you can declare it as a property, and instantiate it in your viewDidLoad
implementation, like so:
self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 200, 320, 100)];
Well, webview suppose to load html code, but not pure string, that might confuse it. If you add <!DOCTYPE HTML>
in front, it can be selected no matter how short the string is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With