In my app I am using a UIScrollView with multiple views (each view having buttons, scrollview and labels). By using for loop I am loading that views into UIScrollView. But when I tried to get touch actions in views inside UIScrollView only last view is able to access. How can we get touch access to all views inside UIScrollView?.
Any help or suggestion to do this.
Just assign tag value to your all yourView then access your view
UIView *yourView = (UIView*)[ScrollView viewWithTag:tag];
Or
NSArray *yourView =(NSArray*)[ScrollView subviews];
NSLog(#"Your subView %#",[yourView objectAtIndex:index]);
Related
I am working on an application where i need to place a uiscrollview within an uiview. The view has a fixed back ground, and in lower half of the view i have to place 30 buttons which scrolls within that area. Lets say the uiview is of 320x480, then the scrollview i have to place will be at (40, 160) to (280, 300). I just need the scroll view to have the 30 buttons inside it. so that view remains fixed, only the buttons can be selected by scrolling vertically. How can i do that?
When i place the scroll view and connect it with file's owner 'view' it eats up all the view space.
Yes, i am a newbie :$
First Add UIScrollView to the view:
UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(40,160,280,300)];
scroll.showsHorizontalScrollIndicator = YES;
[self.view addSubview:scroll];
// Now Add your Buttons on this scrollview;
[scroll addSubview:buttonObject];]
If you wanted to add 30 buttons, you can use 'for' loops to allocate UIButton's and then add it on scrollview.
The UIViewController sub class (your files owner) will only show the one view you connect to it's view outlet. So you should connect the outer view to files owner, and then add the scroll view to the view by dragging it into the view, and sizing it as you like.
You probably want to create another outlet for the scrollview, so that you also have access to the scrollview from your controller. You could to this by adding the following to you controllers h file and then connecting the scroll view in interface builder.
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
Okay, so the subject talks for itself - I need to change default scrollbar with my custom image. I've been looking for a solution that doesn't require you to write your own ScrollView class or use hacks like creating an UIView with scrollbar image and repositioning it as you scroll.
One solution I liked was to use a simple UIScrollView category and to access scrollbars as UIScrollView's subviews: http://leonov.co/2011/04/uiscrollviews-scrollbars-customization/#comment-7909 For some reason, though, this one doesn't work for me. When I create UIScrollView and get its subviews array only views that I manually add to scrollview are shown there. I cannot access scrollbars iterating through subviews array. For example, this code:
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10,10,100,100)];
scrollView.userInteractionEnabled = YES;
scrollView.bounces = NO;
scrollView.showsHorizontalScrollIndicator = YES;
NSLog(#"Subviews count is %d", [[scrollView subviews] count]);
will log "Subviews count is 0". Or, if I add X elements to scrollview, "Subviews count is X". Any ideas?
UIScrollbar scroll views are only created when the view is scrolling. They are removed again when the view stops scrolling. That's probably why you can't find them with your category.
You could move your scrollview subview traversing code into the scrollview delegate's scrollViewDidScroll method, which would mean it gets executed whenever the view is scrolling.
I can't help but feel that this is all a horrible and unneccesary hack though, and you'd be better off hiding the scrollbars and implementing them yourself using the delegate methods to determine when to show and hide your custom scrollbar view and the contentOffset property to determine where to position it.
I want to create a big UIScrollView, its contentView should contain more than 30 UIButton. Positions of these UIButton are not rectiligne and cannot be create 'programmaticaly' so I've placed all these UIButton on a UIView manually. I zoom/dezoom and scroll all over my UIScrollView fine BUT here is my problem : UIButton created offscreen is not accessible, I mean I can't click them (only UIButton created in the CGRect(0.f, 0.f, 320.f, 480.f) can be click.
Any suggestion ?
Create a view, put a scrollView inside that view, and place your buttons on the scrollView. While adding buttons and moving them around, be certain that they're always inside the scrollView by looking at the object hierarchy in interface builder.
You can slide the scrollView around as you place things, no need to zoom. As long as your buttons are children of your scrollView it should work fine.
I need a UIScrollview to show some static content in my app. I have taken a UIScrollView through XIB and started adding some UIImageViews and textViews in to it. But after coming to the end of the scrollView the view is not exapanding anymore. I need more space so that I can add some more views below. Is there any way in which I can do this (through XIB and not through code).
I struggled a lot to get this done in a more elegant way then the solution described by Csabi.
It's really simple:
In your xib file just add a generic view which is not a subview of your viewController.view (i.e although this view is in your xib file, it is not a part of your viewController's view hierarchy.)
Then select this view and using size inspector set the width and height that suits your need. Add whatever objects you want to this view. Hook up this view to your viewController with an IBOutlet. (Let's call it IBOutlet UIView *myBigView).
in your viewController.view drag a ScrollView and adjust the size of the scroll view as you like. Hook this up to your viewController. (IBOutlet UIScrollView *scrollView)
Now it's super simple:
-(void) viewDidLoad{
[super viewDidLoad];
self.scrollView.contentSize = self.myBigView.bounds.size;
[self.scrollView addSubview:self.myBigView];
}
Yes it is you can define the height of the UIScrollView simply for example height:1800
now you get bigger UIScrollView then your view you can put your objects to scrollview, and if it is filled simply pull it upward and drag and drop other items when you are finished simply pull the scroll view to its position and you have it.
It is simple :)
Hope it helps
Ask if you have any other question
I have a UIScrollView in my project. I have a view controller I would like to add as a child of the UIScrollview. Would I just do that like this:
[scrollView addSubview:theViewController.view];
or is there a better way?
(theView is a view, not the TV show)
Furthermore, I would like to be able to use a UIButton in scrollView's parent view controller to toggle whether or not the user is scrolling with scrollView and NOT interacting with theView or NOT scrolling with scrollview and interacting with theView. Should I just have that set the property:
scrollView.userInteractionEnabled = NO;
or would that disable interaction with theView because it's a child?
Thanks for your help!
This is the proper way.
On the scrollView, setScrollEnabled: to turn off scrolling.