Reputation: 9426
This is an update to a earlier question. Once I load up a UIWebView with some string based HTML content, is there a way to determine if the view would require scrolling to see the entirety of the content? I am looking for some sort of flag or way of knowing if content is below the bottom of the UIWebView.
Thanks in advance!
Upvotes: 1
Views: 530
Reputation: 3972
The simplest way is probably to use Javascript to get the document height:
NSInteger height = [[myWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] intValue];
(haven't actually tested this so YMMV. Different browsers put the document height in different objects and properties and I can't remember which one works in Webkit... see How to get height of entire document with JavaScript?)
If the height returned is greater than the UIWebView height it's going to need scrolling.
Upvotes: 0
Reputation: 2429
You could subclass UIWebView and use the following initalizers:
-(id) initWithCoder:(NSCoder *)aDecoder
{
if(self = [super initWithCoder:aDecoder])
{
for (UIView* v in self.subviews){
if ([v isKindOfClass:[UIScrollView class]]){
self.scrollview = (UIScrollView*)v;
break;
}
}
}
return self;
}
- (id) initWithFrame:(CGRect)frame{
if(self = [super initWithFrame:frame])
{
for (UIView* v in self.subviews){
if ([v isKindOfClass:[UIScrollView class]]){
self.scrollview = (UIScrollView*)v;
break;
}
}
}
return self;
}
then have a property called
@property (nonatomic, retain) UIScrollView *scrollview;
You then have access to the scrollview within the UIWebView and can check its content size to see if it is bigger than your views size
Upvotes: 1