2

I am new to iOS, Am facing an issue with UIScrollView. The scroll is not working in this, can you please help me:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 310,300, 999)];

label.text = self.selString;
label.numberOfLines = 0;
// [self.view addSubview:label];

UIImageView *image = 
  [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 300, 300)];
image.backgroundColor = [UIColor greenColor];
image.tag = 50;
image.userInteractionEnabled=YES;
image.autoresizesSubviews = YES;
image.alpha = 0.93;
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://opensum.in/app_test_f1/45djx96.jpg"]]];   // working code
//[self.view addSubview:image];

self.title = @"Full Blog";

CGRect scrollViewFrame = CGRectMake(0,0, 320, 999);
scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.pagingEnabled =YES;
[self.view  addSubview:scrollView];

scrollView.tag=1000;


[scrollView addSubview:label];
[scrollView addSubview:image];
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
  • possible duplicate of [UIScrollView not scrolling](http://stackoverflow.com/questions/2824435/uiscrollview-not-scrolling) – Shamas S Sep 01 '15 at 07:35

4 Answers4

4

Set UIScrollView contentSize :

CGSize contentSize = CGSizeMake([[UIScreen mainScreen]bounds].size.width, 1000);
[scrollView setContentSize:contentSize];
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50
1

You need to set the contentSize of your UIScrollView. Without setting that, it' won't show scrolling. And your contentSize should be bigger than your scrollView.frame.size.

Right now, your scrollView has a huge frame.height. Use a smaller value. And use the higher value for contentSize.height.

Shamas S
  • 7,507
  • 10
  • 46
  • 58
1

Try this code :

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 310,300, 999)];

label.text=self.selString;
label.numberOfLines=0;

UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 300, 300)];
image.backgroundColor = [UIColor greenColor];
image.tag = 50;
image.alpha = 0.93;
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://opensum.in/app_test_f1/45djx96.jpg"]]];

CGRect scrollViewFrame = CGRectMake(0,0, 320, 999);
scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.tag=1000;

[scrollView addSubview:image];
[scrollView addSubview:label];
[self.view  addSubview:scrollView];

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 999);// your scroll scroll height give here
Dharmesh Dhorajiya
  • 3,976
  • 9
  • 30
  • 39
1

set content height of scrollview like this

[scrollView setContentSize:(CGSizeMake(320, 999))];
MrWaqasAhmed
  • 1,479
  • 12
  • 12