Is there any similar solution to UIWebView? - ios

I use a UIWebView in my app to present content, but now I can't do it anymore because I also need to use a UIScrollView and it creates conflicts related to scrolling.
Also, UIWebView is very slow.
So my question is : is there any another way to load string which contains HTML tags (strong, p, div, and etc...)?
UPDATE (improved explanation)
I have UIVIewController containing an image at the top, and under this image is a title and under the title is content (HTML string from web). The problem is that when the text is too big, the webview is scrolling, but not the whole page. I want the whole page to scroll, not just the webview.

You won't get anything faster or better than the native UIWebView. Probably you should overthink your UI/UX. What exactly do you want to achieve with a webview in a scrollview??
Perhaps attributed strings are enough for you. Look it up.
The OHAttributedLabel even parses HTML for you.

Solved.
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *output = [webView stringByEvaluatingJavaScriptFromString:#"document.body.scrollHeight;"];
int webViewHeight = [output intValue];
//NSLog(#"height: %d", webViewHeight);
if(webViewHeight > 220){
CGRect frame = articleContentWebView.frame;
frame.size.height = webViewHeight;
articleContentWebView.frame = frame;
int scrollViewheight = 416 + (webViewHeight - 220);
[articleScrollView setContentSize:CGSizeMake(320, scrollViewheight)];
}
}
In delegate method webViewDidFinishLoad I calculate height od UIWebView content and then set height of UIWebVIew and height of UIScrollView.

Related

How to increase max height of UITextView beyond 10000 in iOS?

I have a huge text to display in iOS UITextView which makes the height around 40000 but in XCode it says it cannot support size larger than 10000 by 10000.
Any solutions?
Thanks.
The short answer is: you're doing it wrong.
A UITextView already allows scrolling through text. You don't make the view large enough to display the text, you make it large enough to fit on screen, and even in the macOS world, 10Kx10K is larger than any possible screen dimensions.
so many text that size over 10000 ,I advice you to use UiWebview or UILable replace UITextField. I hope I can help you.
-(UIWebView*)XueweiwebView {
if (!_XueweiwebView) {
_XueweiwebView = [[UIWebView alloc]init];
_XueweiwebView.frame = self.tableView.frame;
_XueweiwebView.delegate = self;
_XueweiwebView.scrollView.bounces = NO;
NSString* str = #"<p>here is many text you can plae 4000 charater or more</p>";
[_XueweiwebView loadHTMLString:str baseURL:nil];
[self.view addSubview:_XueweiwebView];
}
return _XueweiwebView;
}
NSString* str = #"<p> place your text 40000 </p>";

Unable to fit webpage in UIWebView in ios?

I am displaying a webpage in UIWebview. My webpage looks good on the browser, but on iPhone 5s the view does not fit. It is much too large, so I want to know how I can fit the content.
I have used ScalePageToFit & sizeTofit but nothing is working.
set your web view delegate and frame.
yourwebview.frame=[[UIScreen mainScreen] bounds];
yourwebview.delegate = self;
end then use this delegate method to set height.
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
CGSize contentSize = aWebView.scrollView.contentSize;
NSLog(#"webView contentSize: %#", NSStringFromCGSize(contentSize));
yourwebview.contentsize = contentSize;
}
OR
also See my answer at How to make iOS UIWebView display a mobile website correctly?
lets try this, some web pages doesn't responds to scalesPageToFit try this not sure , just give it a try
//those web pages can handle only once the web page is loaded completely
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if ([_webView respondsToSelector:#selector(scrollView)])
{
UIScrollView *scroll = [_webView scrollView];
float zoom = ((_webView.bounds.size.width + 20 )/scroll.contentSize.width) - 0.30;
[scroll setZoomScale:zoom animated:YES];
}
}

How can I scale the fixed size html content to fit the UIwebview frame size?(the content size is much smaller than the frame size)

I am now doing a advertSDK project like inmobi, the user is allowed to create the banner frame and locate them by CGrectmake, so I will create a UIWebview as they required, then in the UIwebview I just to load the html content to show it in the right position.
The question is: the banner content has a fixed size : 360 * 100, however in iphone 6s simulator, it is too small, I tried to set
webView.scalesPageToFit = YES
but it has no effects.
Anyone has a good idea to solve the problem? Thank you.
You have to use the UIWebView delegate methods and resize the web view like I'm doing here:
- (void) webViewDidFinishLoad:(UIWebView *)webView {
webView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y, webView.frame.size.width, webView.scrollView.contentSize.height);
}

Get height of UIWebView loaded content

So what I am after is a way to put a UIButton on top of a UIScrollView and a UIWebView under it. The reason I want it this way is that I need the button to "scroll away" as the user scrolls the page I load into the UIWebView.
In order for this to work, I need to get the height of the content of the web page I load and then set the height of the web view to match this. If I can do this, I then intend to set the contentSize of the UIScrollView to match the heights of the button and web view.
I understand that somehow this is supposed to happen in the - (void)webViewDidStartLoad:(UIWebView *)webView method, which is confirmed on many threads on stackoverflow (for example this one). I also know that Apple says you shouldn't put a UiWebView in a UIScrollView, since the scrolling actions may interfere. Disabling scroll for the web view should avoid the problem though.
There are many threads discussing this matter, but none of them seem to work for me. Can it be because I am running on iOS7?
I am in big desperation here, help is much appreciated!
You can get height using following code :
NSString *heightStrig = [webView stringByEvaluatingJavaScriptFromString:#"(document.height !== undefined) ? document.height : document.body.offsetHeight;"];
float height = heightStrig.floatValue;
complete code :
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
CGRect frame = webView.frame;
NSString *heightStrig = [webView stringByEvaluatingJavaScriptFromString:#"(document.height !== undefined) ? document.height : document.body.offsetHeight;"];
float height = heightStrig.floatValue + 10.0;
frame.size.height = height;
webView.frame = frame;
}
You can get the height of the content loaded into a UIWebView as follows:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
CGFloat contentHeight = webView.scrollView.contentSize.height;
}
And then adjust the frame of the web view accordingly.

Determine height of UIWebView content (embedded in UITableViewCell)

I've got a UITableView holding UIWebViews of variable height, and the user has the ability to edit the content of each web view. The content of each cell (a web view) is linked to a NSManagedObject subclass that has the height of the content stored as contentHeight. When a new set of content is initially created, it is filled in with a default set of data that has a set height, so there is no issue there.
My problem arises when the user edits the content of a web view; I need to figure out the height of the new content and update the tableview accordingly. I've already set up the logic for updating the saved contentHeight variable for the corresponding object, but I cannot find a reliable method to determine the height of the new content. Below I've listed a few of the methods I've tried and haven't been able to make work. ANY help would be greatly appreciated, I've been stumped for over an hour now :(
FAILED METHODS:
[[webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.scrollHeight"] floatValue];
[[webView stringByEvaluatingJavaScriptFromString:#"document.body.scrollHeight"] floatValue];
[[webView stringByEvaluatingJavaScriptFromString:#"document.body.offsetHeight"] floatValue];
[[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('sdcontent').offsetHeight"] floatValue];
CGRect webViewFrame = [webView frame];
CGRect temp = webViewFrame;
webViewFrame.size.height = 1;
[webView setFrame:webViewFrame];
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
webViewFrame.size = fittingSize;
[webView setFrame:temp];
it works but only when
making webview small (like 5px)
load it and wait for finish
calling sizeToFit on it then
getting the size THEN
advertisement: :D see my M42WebviewTableViewCell class on github which struggles with this

Resources