0
votes

In one of my viewController, I have a scrollView, a UIView which contains and UIImageView, UITextView etc. for the scrollview here's the code what i wrote:

    overViewScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
        [overViewScroll setCanCancelContentTouches:NO];
        overViewScroll.pagingEnabled = YES;
        overViewScroll.clipsToBounds = NO;
        overViewScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
        [overViewScroll setContentSize:CGSizeMake(screenFrame.size.width, screenFrame.size.height-25)];
        [overViewScroll setScrollEnabled:YES];
        [overViewScroll setAlwaysBounceVertical:YES];
        [overViewScroll setShowsVerticalScrollIndicator:YES];

UIView * completeView = [[UIView alloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
    UILabel* heading1 = [[UILabel alloc]initWithFrame:CGRectMake(5,0,310,30)];
    heading1.text = name;
    heading1.backgroundColor = [UIColor clearColor];
    UIFont * headingFont = [UIFont fontWithName:@"HelVetica" size:15];
    heading1.font = headingFont;
    [completeView addSubview:heading1];
    //NSSet * imageString = [projectHeroData valueForKey:@"imageURL"];
    NSString * urlString = @"";
    NSURL * url = [NSURL URLWithString:urlString];
    NSData * imageData = [NSData dataWithContentsOfURL:url];
    UIImage * projImage = [[UIImage alloc]initWithData:imageData];  
    UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,screenFrame.size.height/50,screenFrame.size.width-((screenFrame.size.width/70)*2),screenFrame.size.height/3)];
    imgView.image = projImage;
    imgView.backgroundColor = [UIColor blueColor];
    [completeView addSubview:imgView];

    UILabel * abstract = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width/4,screenFrame.size.height/30)];
    abstract.text = @"Abstract-";
    abstract.font = [UIFont boldSystemFontOfSize:fontSize];
    abstract.backgroundColor = [UIColor clearColor];
    [completeView addSubview:abstract];

    UILabel * lastUpdated = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41 + screenFrame.size.width/5,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width-screenFrame.size.width/4,screenFrame.size.height/30)];
    NSString * string = modDate ;
    NSString * updated = [NSString stringWithFormat:@"Last Updated-%@",string];
    lastUpdated.text = updated;
    lastUpdated.backgroundColor = [UIColor clearColor];
    lastUpdated.font = [UIFont boldSystemFontOfSize:fontSize];
    [completeView addSubview:lastUpdated];

    UITextView * textView2 = [[UITextView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,(screenFrame.size.height/31 + screenFrame.size.height/3)+screenFrame.size.height/30,screenFrame.size.width-screenFrame.size.width/70*2,screenFrame.size.height)];
    textView2.text = abst;
    textView2.editable = NO;
    textView2.font = [UIFont systemFontOfSize:fontSize];
    textView2.backgroundColor = [UIColor clearColor];
    [completeView addSubview:textView2];

    [overViewScroll addSubview:completeView];
    [self.view addSubview:overViewScroll];

everything is addded to the UIView and UIView is added to the UIScrollView. But the problem is its behaving weird, image is not scrolling all the way through and the text in Textview is scrolling in itself. Please help!!

2
change the contentsize of your scrollview - ajay
what should i do increase it or decrease it?? - Ashutosh
when ever you want scroll then the scrollview contentsize must be greater than its subview.means in your case uiview frame size is less than the uiscrollview - ajay

2 Answers

0
votes

change the contentsize of your scrollview.your UIview size and uiscrollview size is same if the UIScrollview contentsize is more than its subview size then scroll will happen change the line [overViewScroll setContentSize:CGSizeMake(screenFrame.size.width, screenFrame.size.height-25)]; like this [overViewScroll setContentSize:CGSizeMake(screenFrame.size.width, (screenFrame.size.height-25)*2)];.it will allow you to horizontal scroll And by default textview having scroll property its self.

0
votes
 overViewScroll =[[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
    [overViewScroll setCanCancelContentTouches:NO];
    overViewScroll.pagingEnabled = YES;
    overViewScroll.clipsToBounds = NO;
    overViewScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    [overViewScroll setContentSize:CGSizeMake(320,600)];
    [overViewScroll setScrollEnabled:YES];
    [overViewScroll setAlwaysBounceVertical:YES];
    [overViewScroll setShowsVerticalScrollIndicator:YES];

 UIView * completeView = [[UIView alloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
UILabel* heading1 = [[UILabel alloc]initWithFrame:CGRectMake(5,0,310,30)];
heading1.text = name;
heading1.backgroundColor = [UIColor clearColor];
UIFont * headingFont = [UIFont fontWithName:@"HelVetica" size:15];
heading1.font = headingFont;
[completeView addSubview:heading1];
//NSSet * imageString = [projectHeroData valueForKey:@"imageURL"];
NSString * urlString = @"";
NSURL * url = [NSURL URLWithString:urlString];
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage * projImage = [[UIImage alloc]initWithData:imageData];  
UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,screenFrame.size.height/50,screenFrame.size.width-((screenFrame.size.width/70)*2),screenFrame.size.height/3)];
imgView.image = projImage;
imgView.backgroundColor = [UIColor blueColor];
[completeView addSubview:imgView];

UILabel * abstract = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width/4,screenFrame.size.height/30)];
abstract.text = @"Abstract-";
abstract.font = [UIFont boldSystemFontOfSize:fontSize];
abstract.backgroundColor = [UIColor clearColor];
[completeView addSubview:abstract];

UILabel * lastUpdated = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41 + screenFrame.size.width/5,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width-screenFrame.size.width/4,screenFrame.size.height/30)];
NSString * string = modDate ;
NSString * updated = [NSString stringWithFormat:@"Last Updated-%@",string];
lastUpdated.text = updated;
lastUpdated.backgroundColor = [UIColor clearColor];
lastUpdated.font = [UIFont boldSystemFontOfSize:fontSize];
[completeView addSubview:lastUpdated];

UITextView * textView2 = [[UITextView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,(screenFrame.size.height/31 + screenFrame.size.height/3)+screenFrame.size.height/30,screenFrame.size.width-screenFrame.size.width/70*2,screenFrame.size.height)];
textView2.text = abst;
textView2.editable = NO;
textView2.font = [UIFont systemFontOfSize:fontSize];
textView2.backgroundColor = [UIColor clearColor];
[completeView addSubview:textView2];

[overViewScroll addSubview:completeView];
[self.view addSubview:overViewScroll];

try this it will work. another way is u yse interface builder and select scoll view and drag and drop other label image view on scroll view.