How to make a scrollable view in iOS? - iphone

i am looking to create an "options" page for my application and because they are many , the screen of the phone is not enough to show.
So i need the user to be able to scroll down the view to see more options till the last. I know i should use the scrollview , but i dont know how.
All the tutorials i ve found are about scrolling all over the screen , zooming , scrolling from left to right , but nothing on how u can create a simple page scrolling up and down.
How exactly do i do that? Do i make many .nib files and somehow i connect them? Do i make a big .nib file?
Can someone guide me to a tutorial on that?

Use ContentSize property of UIScrollView to scroll what ever area you want. i.e.
take UIScrollView add it on UIView with exist height of iPhone. i.e. max 460.0
So ScrollView frame will be max (0,0,320.0,460.0).
Now after adidng ScrollView to View set ContentSize property to upto scrollable area.
[self.mainScrollView setContentSize:CGSizeMake(self.mainScrollView.frame.size.width, 1000.0)];

UIScrollView *mainScroll = [[[UIScrollView alloc]initWithFrame:CGRectMake(x,y,w,h)]autorelease];//scrollview width and height
mainScroll.scrollEnabled = YES;
mainScroll.userInteractionEnabled = YES;
mainScroll.showsVerticalScrollIndicator = YES;
mainScroll.contentSize = CGSizeMake(width,height);//width and height depends your scroll area
..........
//add subviews to your scrollview.....
[mainScroll addSubview:view1]
............
[mainScroll addSubview:view2]
..............
[mainScroll addSubview:view3]
[self.view addSubview:mainScroll];
Note :: contentSize property determines your scroll
area.Scrolling
enabled only if your scrollview content larger than scrollview height..

You could use a Table View with static Cells, that will scroll automatically if it needs to, much easier. Also with a Table View you can choose to scroll up, down, left, right, set bouncing etc from the Attributes Inspector.

Make only 1 nib file.
give height of scroll view large as you want.
then place your buttons , textfeild on scroll view

There are two ways :
make settings bundel for your app check this Press Me
to make UITableView with custom cells >> it is easy if you use
Interface Builder Press Me

Related

How to scroll a simple UIView (not uitableview) in iphone?

I have added some uitextview in my uiviewcontroller.But some of the textViews are not seen as view is small compared to the number of textViews. So I want scroll it, so that i can see the other textViews also. One more thing-- when i want to type something in the lower textView then it hides because of the iphone keyboard.If somebody knows about it, please give me with the solution.Thanks a lot.
Add UIScrollView in self.view. Now add all subviews to UIScrollView.
Provide contentSize of UIScrollView in width and height.
if heigth > 460 it will scroll vertically
if weight > 320 it will scroll horizontally
If any condition doesnot matches then u will not be able to scroll
You simply have to use UIScrollView.Instead of adding all of your subviews(in your case multiple UITextViews) in the main view, just add a srollView in your view and then add all subviews in that scrollView.UIView doesn't have the property to scroll.And don't forget to change the contentSize property of scrollView.
You must implement a UIScrollView. This is a fundamental class when it comes to iPhone development (and just Apple development in general) and it should be mastered before you continue onto more advanced topics. Here is the documentation for the class :
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html

label and scroll view

HI FRIENDS..
I use a scroll view and a label now i want that when i scroll that , label also scroll with that and set to next location , i set paging enable = YES , so i want that there are 5 images and when i did scrolling the label i set is also move and show in other position.
thanks
To scroll a UILabel (or anything for that matter) WITH a UIScrollView, simply add the label to the UIScrollView.
You can easily do this in Interface Builder by the obvious methods.
You can also do this programmatically by utilizing the addSubview: method.
You can do one thing you change frame of label when you scroll in delegate method of scrollview or you can also make 5 same label in all 5 pages.
Good Luck
Well if you have added a scrollview on top of a uiview you can add that label on the view and then bring it to front. then you dont have to worry about changing frame of the uilabel as it will be always on top of the scrollview and at the same position and also you can change the text of that label when the user scrolls in pagecontrol value changed method.

UIScrollView won't scroll!

In IB I have my UIView. Then I have a sub-UIView with a UIScrollView as a sub view. Then the UIScrollView has a sub-UIImageView. The UIScrollView and UIImageView are the same size. They're much bigger than the UIView of which they are subviews. I assumed this would make scrolling work. It doesn't. Is some sort of code required for scroll views to work?
You need to set UIScrollView.contentSize to match the total scrollable size, which is your subview frame size in this case.
As mentioned in the accepted answer, you must set the UIScrollView's contentSize property.
This can be done in Interface Builder.
Select the scroll view
Select the 'identity inspect' in Utilities pane on the right
Under 'User Defined Runtime Attributes' click the '+' button
Set the 'Key Path' value to 'contentSize'
Set the 'Type' value to 'Size'
Set the 'Value' value to '{width, height}' (eg: '{320, 600}')
Build and run and your scroll view will scroll.
The content inset does not affect scrolling. See What's the UIScrollView contentInset property for?
To scroll, you have to make the scrollview's frame smaller than its content, the contained image or view.
This might be obvious to most, but I spent ages wondering why my UIScrollView wouldn't scroll so I'm posting what was stopping me in case it helps anyone else:
The UIScrollView has to be of the dimensions of the visible area in which you wish it to be presented and not the size of it's contents.
Ridiculous on my behalf I know, but just in case it helps someone.
I placed all the content of my scrollview in IB. (buttons, labels, text fields, etc). The full size is 500 tall.
I then resized it to 436 tall in IB.
Then in code, I put this is viewDidLoad:
optionsScrollView.contentSize = CGSizeMake(320,500);
So that leaves 64 pixels that I can scroll. It works perfectly.
I also placed "UIScrollViewDelegate" in the <> braces of #interface for my .h file and tied the delegate outlet of the scrollview to File's owner in IB.
I could solve the scrolling problem with the following answer:
https://stackoverflow.com/a/39945124/5056173
By me the trick was:
You now need to set the height of the content UIView. You can then either specify the height of the content view (blech) or use the
height of the controls contained within by making sure the bottom
control is constrained to the bottom of the content view.
I have set the height and width of the view inside the scrollView with center vertical and horizontal alignment and that was the reason, why it did not work!
After deleting this constraints, I need to add equal width (scrollView and the view inside the scrollView) AND I set the height of the view inside the scrollView directly with the content. Which means: The last element in the view must have a bottom constraint to the view!!
The other important thing that I don't see mentioned here is that UIScrollView does not play nicely with AutoLayout. If it seems like you've done everything correctly, check if your ViewController has autolayout turned on and, if so, turn it off.
(Every time you scroll, the views are re-laid-out. Gak!)
So:
Make sure scrollview's contentSize is bigger than its frame.size
Make sure AutoLayout for the ViewController is turned off.
more, did you enable scrolling?
look at the property
#property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled
Make sure 3 things,
checking scrollView frame & contentView frame, u may find the answer
scrollView.isScrollEnabled = true
contentView of scrollView height didn't constraint with scroll view height
UIScrollView won't scroll!
reason: contentSize is same as (sub) view
should: contentSize is large than (sub) view
-> UIScrollView can scroll
how set UIScrollView contentSize?
two method:
in code
- (void)viewDidLoad {
[super viewDidLoad];
。。。
//[(UIScrollView *)self.view setContentSize:CGSizeMake(375, 1000)];
CGSize curScreenSize = UIScreen.mainScreen.bounds.size;
CGFloat scrollWidth = curScreenSize.width;
CGFloat scrollHeight = curScreenSize.height * 2;
[(UIScrollView *)self.view setContentSize:CGSizeMake(scrollWidth, scrollHeight)];
in UI (Storyboard)
Storyboard-》Identity Inspector-》User Defined Runtime Attributes-》 add new attribute:
contentSize
Type:Size
Value:{375, 1000}
Scroll view works with this:
Frame
then
contentSize
views or objects etc...
If your frame is set to your content size then it won't scroll.
So set your frame ( in IB right panel -> second last tab 'Size Inspector") to the length of your app ( in my case it is 367 as i have a navbar and a tab bar) then programatically set the contentSize to - yup you guessed it ... more than your frame so it can scroll.
Happy days!!

IPhone App: UIScrollView scrolls to bottom when it loads

I have a detail view for a contact. The last field is a Textview that can be as short as 1 line and as long as 20. in the viewDidLoad method I use:
scrollView.contentSize = self.view.frame.size;
My problem is that when the data is displayed, the scroll view scrolls to the bottom on its own. Obviously I would like it to start at the top.
I used the Content offset with the bottom value set to about 300 to allow the view to even be able to scroll down far enough. I have tried to disable scrolling until the load is finished but then it just locks you at the bottom.
As you can probably tell I am new at iPhone Programming. Any ideas?
Set contentOffset to 0.
Then, go and read the docs. you're using the scroll view completely wrong.
UITextView is scrollable, so it's unclear why you're sticking it in a scroll view.

iphone, need to put many text boxes on the view, how to scroll down to view more content?

iphone, need to put many text boxes on the view, how to scroll down to view more content? I actually put buttons and labels on the ScrollView, but the scrolling doesn't work. Do I need to write any code for that, any example?
Thanks.
You need to set the contentSize property of the UIScrollView to something bigger than its frame size.
[aScrollView setContentSize:CGSizeMake(320, 1000)];