Reputation: 117
I have scrollview bottom of the screen. when i click the button it load the scrollview. But the scrollview is occupies full parentview. I can't control bottom the view for some rectMake. If i use scrollview i can't handle some other button actions and click event for other subviews.
code:
scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,self.view.frame.size.height)];
scrollview.scrollEnabled=YES;
for (int i = 0; i<[self.array count]; i++ ) {
NSLog(@"index %d",i);
imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 500, 72, 72)];
[imgView1 setTag:i+1];
[imgView1 addTarget:self action:@selector(Clicked:) forControlEvents:UIControlEventTouchUpInside];
[imgView1 setImage:((Mysof *)[self.array objectAtIndex:i]).photo forState:UIControlStateNormal];
[scrollview addSubview:imgView1];
}
[scrollview setContentSize:CGSizeMake(CGRectGetMaxX(imgView1.frame),self.view.frame.size.height)];
[self.view addSubview:scrollview];
Log:
scroll is <UIScrollView: 0x1f03d550; frame = (0 0; 320 568); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x1f037090>; layer = <CALayer: 0x1f036670>; contentOffset: {0, 0}>
Upvotes: 1
Views: 98
Reputation: 3130
You are doing like this:
scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,self.view.frame.size.height)];
instead Try this:
int y = self.view.frame.origin.y+ self.view.frame.size.height-200;
scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,y,320,200)];
Here, Scrollview will be displayed at bottom of the view and it will be of 320X200 size. you can change the height as per your requirements. when you change Height then also change value at self.view.frame.origin.y+ self.view.frame.size.height-changedHeight.
and make Imageview Frame Like this:
imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 0, 72, 72)];
Content size should be smaller then scrollview height for only horizontal scroll. Here, Width should be total of your all imageview's width+ given space. so i would say that try using Width variable like this in your for loop and use that Width to content size so it would set as per total width of images.
int Width = 0;
for (int i = 0; i<[self.array count]; i++ ) {
Width = Width + 20+(i*74);
}
[scrollview setContentSize:CGSizeMake(Width,imgView1.frame.size.height+20)];
Hope it Helps!!
Upvotes: 2
Reputation: 5955
Set the scrollView's height as a origin of the bottom button,
scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,400)];
Here i assume that your button/ bottom view's y position as 400. Instead you can change as your need
Upvotes: 0