Sending an item to be inside the scrollView - iphone

I created a segmentedControl and add it as subView during viewDidLoad. I faced a problem whereby it doesn't scroll.
How do I add a subView to be inside the scrollView?
Thanks.

Figured out...
[scrollView addSubview:segmentedControl];

[scrollView addSubview:segmentedControl];
scrollView.contentSize = CGSizeMake(s.frame.size.width, 1000);
change height accordingly your segmentedControl height.
if your segmentedControl is fit in scrollview it would not scroll.

Related

Add scrollview iOS Objective-C

I have the following code in viewDidLoad on my ViewController:
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:204.0/255 green:00.0/255 blue:00.0/255 alpha:1];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
autoNameLabel.text = (NSString *)[vendorDetails objectForKey:#"autoname"];
homeLabel.text = (NSString *)[vendorDetails objectForKey:#"homelab"];
descriptionTextView.text = (NSString *)[vendorDetails objectForKey:#"description"];
This all fits perfectly on the view. I know need to add an additional textView on the bottom so need the user to be able to scroll to see it. How can I add this info to a scrollable view and add my additional textView?
you could have your UIViewController extend UISCrollViewController. Or you could add a UIScrollView to your view controller's view in the method viewDidLoad. Then add all subviews of your view to the scrollview instead.
self.scrollView = [[UIScrollView all] initWithFrame:self.view.bounds]
self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.width, HEIGHT_OF_SCROLLABLE_AREA).
I would also do something like this for the scroll view height if your last textview is named lastTextView
HEIGHT_OF_SCROLLABLE_AREA = CGRectGetMaxY(lastTextView.frame + bottomPadding)
Are you sure you dragged all the other views on the scrollview? Make sure the contentSize of the scrollview is high enough(you know, higher than the screen) to scroll.
have u set delegate of UIScrollView. if you have not set delegate of UIScrollView then also it may possible that your scroll is not working.

How to overlay a view above another view?

As suggested by jjv360 in another question of mine, one way to have a customized paging width for a scrollView is to make scrollView be the size for paging, and then overlaying a transparent UIView over it and doing [overlayView addGestureRecognizer:scrollView.panGestureRecognizer] for the touch event.
This sounds like a great idea and here is my quick question:
Is overlaying just [view addsubview OLvier] ? What is the views overlaying method?
Yup... Set the views frame using CGRectMake and overlay using
[scrollview addsubview: view1]
UIView *yourView = [UIView alloc]init];
yourView.frame = CGRectMake(x,y,width,height)//whatever values work for you
[self.view addSubview: yourView];

How to add a textview in Uiscrollview?

Using storyboard i want to add UITextview in the UIScrollview and the scroll the TextView in the in the screen. please help me...
scroller.contentSize=CGSizeMake(320,846);
[scroller setScrollEnabled:YES];
int GetIndex = [GetSelectedIndex intValue];
label = [firstheading objectAtIndex:GetIndex];
labelheading.text=label;
textviews = [firstdesc objectAtIndex:GetIndex];
textview.text=textviews;
[scroller addSubview:textview];
NSLog(#"textview:%#",textview);
NSLog(#"image:%#",getimage);
Just a suggestion, you could try adding a UIView on your ViewController first.
Then drag the UIScrollView into your UIView.
Then drag a UITextView into that.
I have this arrangement in a Storyboard - because I have an image in the top level UIView as well as the UIScrollView

Cannot interact with UIScrollView

Before you bash me for duplicate, please know that I have looked nearly every other method but none of them have helped. I have a long view in which I have a scroll view.
The view is 320 by 671. The scroll view has been linked to the outlet "scrollView" correctly.
The property "scrollView" has been properly declared and synthesised.
My code:
[scrollView setScrollEnabled: YES];
scrollView.contentSize = CGSizeMake(320, 671);
scrollView.clipsToBounds = YES;
scrollView.delegate = self; // I have adopted the delegate protocol in .h
So, my problem is that the view doesn't scroll, and the scroll bar doesn't even show up.
EDIT:
I resized the uiview to normal 320 by 460. I deleted the scroll view in xib and decided to add like this:
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(self.view.center.x, self.view.center.y, 320, 460)];
[scrollView setScrollEnabled: YES];
scrollView.contentSize = CGSizeMake(320, 671);
scrollView.clipsToBounds = YES; scrollView.delegate = self;
[self.view addSubview: scrollView];
OK, now what happens is when I scroll the screen, the bar comes up and I can scroll around to change the bar's position, but the actual view doesn't scroll
You need set the ContentSize of UIScrollView to the size of your CONTENT.
Do not set "ContentSize" to the size of the view. The "Content Size" should tell the size of the content within the scroll view.
Your scrollview should be 320x460 and your scrollview.contentsize should be 320x671.
You must layout your subviews "outside" of the view in IB.
EDIT:
Your layout should look like this:
http://ge.tt/api/1/files/4qGbz2N/2/blob/x675
The textview is placed outside the views frame but inside the scrollview. The scrollviews content size should be set accordingly to fit all subviews. In this case yValue should be 550 + 128

UIScrollView inside UIView

I'm with a project in which I have a UIScrollView inside a UIView. Inside the UIScrollView has to see a list of buttons in 3 columns and X rows. I have the code that displays the buttons, but does not inserted into the UIScrollView, it prints over and does not scroll. Besides this, also cover the TabBar I have in the bottom of the view.
The code of the function that displais the buttons is
for (int y_axis=0; y_axis<=3; y_axis++)
{
for (int x_axis=0; x_axis<=2; x_axis++)
{
UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(16+100*x_axis,100.0+115*y_axis,88.0 ,88.0)];
btn.backgroundColor=[UIColor brownColor];
[self.view addSubview:btn];
}
}
How can I do to display this in the UIScrollView? Thanks!!
Assuming you have a UIScrollView scroller, you have to change your last line to this;
[self.scroller addSubview:btn];
If not, you are adding it to the view, and not the scroller. Also, you have to change the scrollers contentsize, which is the X*Y if how much it contains. For it to contain the whole screen and nothing more;
[self.scroller setContentSize:CGSizeMake(320, 480)]
^ ^
Replace that with the width and the height you want to scroll. Each time you add a button below your new buttons, you should update the contentsize.
It's because you are adding buttons on view [self.view addSubview:btn]; not on ScrollView. Try to make a view with all you buttons. and set your view with buttons as contentview of your scrollview .
first you need the UIScrollViewDelegate in your .h file and then also check buttons are subview of yourScrollView or not also you add this button in your scrollview with code like this bellow...
[yourScrollView addSubview:yourbuttonname];
after that in your viewDidLoad method declare contentsize of your scrollview like this...
yourScrollView.contentSize=CGSizeMake(320, anyheight);///here define height which you want to scroll the view...
hope this help you....
:)
Try these steps:
for loop
{
create buttons along with the desired frames;
add those buttons to scrollview;
}
set the content size of the scrollview according to no of rows;
add the scroll view to main view i.e. self.view;