Reputation: 159
I have placed a UIScrollView
in a ViewController
in IB
and gave the view the tag:1
. In viewDidLoad:
, I have this code:
UIScrollView *scrollView = (id)[self.view viewWithTag:1];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.opaque = NO;
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)];
I have a slider and a label in the ScrollView
just to see if it scrolls, but it doesn't scroll at all. I get to change the backgroundColor
to for example yellowColor
, but it doesn't scroll. Is there a method or action i have to add? Please help! :)
Upvotes: 1
Views: 488
Reputation: 1070
I had the same problem not long ago, but this did the trick.
Use -(void)viewDidAppear:(BOOL)animated { ... }
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.opaque = NO;
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)];
[super viewDidLoad];
}
Also declare the UIScrollView in your header
@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
Upvotes: 2
Reputation: 6342
try to add this code in viewWillAppear
UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:1];
scrollView.frame=CGRectMake(0, 0, 320, 400);
scrollView.backgroundColor = [UIColor clearColor];
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)];
[scrollView setUserInteractionEnabled:YES];
hope will help you
Upvotes: 0
Reputation: 2061
Try Like this
UIScrollView *scrollView = (id)[self.view viewWithTag:1];
scrollView.frame=CGRectMake(0, 0, 320, 460);
[self.view addSubview:scrollView];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.opaque = NO;
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)];
because when the scroll view height cross the current view height then only its get scrollable.
Upvotes: 2
Reputation: 20541
here may be its problem with set TopBar of UIView
with UINavigationBar
from xib and also BottomBar of that... Here from XIB first select main UIView
after click on Attribute Inspector
after in Simulated metrics set NavigationBar as a TopBar and after set frame of UIScrollView
in XIB
.
try with bellow code it will worked ..
[scrollView setContentSize:CGSizeMake(320, 844)];
Upvotes: 0
Reputation: 1625
scrollView.backgroundColor = [UIColor clearColor];
change this to something bright like red or green for testing.
UIScrollView *scrollView = (id)[self.view viewWithTag:1];
scrollView.backgroundColor = [UIColor clearColor];
also make sure your scrollview isnt nil (after obtaining from [self.view viewWithtag:1]
. otherwise the code seems OK
EDIT
select scroll view in interface builder > go to attributes editor > tick scrolling enabled
Upvotes: 0