I have a controller in my project that contains three UILabels
(Title, Creator and Date Published) and a UIWebView
at bottom that is showing html
using loadHtmlString
. Right now UIWebView
is able to scroll at the bottom while labels are kept static on the screen. What i want to do is to scroll all of them together. If anyone can help how to do it in StoryBoards.
Asked
Active
Viewed 868 times
2

Rajneesh071
- 30,846
- 15
- 61
- 74

Jessica
- 1,508
- 15
- 25
-
I may be wrong but I do not think any of those proposed solutions will work. Adding the labels and web view to a scrollview will mean that the webview will scroll independently of the scrollview which equals a bad/frustrating user experience. I would look into the scrollview delegate methods. Webviews conform to this. Animate the frames of the labels with the value of the content offset of the webview's scrolling. – bennythemink Dec 21 '12 at 06:16
-
you should create a UIScrollView to contain all your scrolling content. Then, set your web view to be non-scrollable. – nielsbot Dec 21 '12 at 07:29
3 Answers
4
just add this UILable
and UIWebView
as a subview of UIScrollView
.. and
in - (void)webViewDidFinishLoad:(UIWebView *)webView {" delegate method I detect the size of the UIWebView
method just set contentSize of WebView and also scrollView like bellow...
[yourWebView setContentSize:CGSizeMake(320, yourWebView.contentSize.height)];
[yourScrollView setContentSize:CGSizeMake(320, scrView.frame.origin.y + yourWebView.contentSize.height)];
just set frame this whole control with your requirement...
hope this help you...

Jessica
- 1,508
- 15
- 25

Paras Joshi
- 20,427
- 11
- 57
- 70
-
i have tried it. All it does is add the scrolling effect to the labels as well but as soon as the labels are scrolled up, the webview at bottom still scrolls separately. – Jessica Dec 21 '12 at 05:28
-
@Jessica what you want dear?? i think you want that webview not scrollable but when you scroll whole scrollview scroll with this whole controll right?? – Paras Joshi Dec 21 '12 at 05:30
-
-
oh ok then do this [yourWebView setUserInteractionEnabled:NO]; and also set the webview height which you want and after set scrollview content height so you scroll end of the webview.. :) – Paras Joshi Dec 21 '12 at 05:39
-
setUserInteractionEnabled:No is making the scroll the way i want. Half problem is done. But i am not sure about setting the scrollview hight because it varies as i am loading the webview with loadHtmlString function – Jessica Dec 21 '12 at 06:09
-
@Jessica hey just set conentsize of webview and after scrollview see this answer dear http://stackoverflow.com/questions/3525256/how-to-set-content-offset-and-content-size-in-a-uiwebview hope this help you... also you can set the size like [scrView setContentSize:CGSizeMake(320, 520)]; and also for webview same as with [webview setContentSize:CGSizeMake(320, webview.contentSize.height)]; :) see the link here – Paras Joshi Dec 21 '12 at 06:16
-
-
@Jessica you try this code dear?? and +1 for your good answer with starting point... :) – Paras Joshi Dec 21 '12 at 06:43
-
Yes i think i will be able to do this with the link you shared. The code you provided won't work for me as i am not using webViewDidFinishLoad, instead i am using loadHtmlString from the data parsed using NSXMLParser. I will get back and sum up everything – Jessica Dec 21 '12 at 07:08
-
yes dear just think about concept.. see when your webview load complete then just set frame with my code dude.. its very simple use the flow... – Paras Joshi Dec 21 '12 at 07:10
0
Add a UIScrollView to your View. Add the labels and the UIWebView to the UIScrollview. Here is how it would look in Interface Builder.

DenVog
- 4,226
- 3
- 43
- 72
-
Do i need to configure ScrollView or not. Because earlier i tried it that way but it didn't work. – Jessica Dec 21 '12 at 02:40
-
I have tried that before posting this question but the thing is that even i have added labels as a subview of scrollview, the bottom webview still scrolls separately so this isn't what i wanted. – Jessica Dec 21 '12 at 05:26
0
See this link may it helps you: http://atastypixel.com/blog/a-drop-in-universal-solution-for-moving-text-fields-out-of-the-way-of-the-keyboard/comment-page-1/
You should try to implement TPKeyboardAvoidingScrollView in your code. See this link.

Vishal
- 8,246
- 6
- 37
- 52