Uiscrollview does not scroll horizontally

My UIScrollView below does not scroll horizontally, please help me here.

FirstView = [[UIView alloc] initWithFrame:CGRectMake(60, 0, 100, 150)]; [FirstView setBackgroundColor:[UIColor clearColor]]; SecondView = [[UIView alloc] initWithFrame:CGRectMake(320+60, 0, 100, 150)]; [SecondView setBackgroundColor:[UIColor clearColor]]; HolderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1000, 150)]; scrHorizontalScroll = [[UIScrollView alloc]initWithFrame:HolderView.frame]; [scrHorizontalScroll setBackgroundColor:[UIColor redColor]]; [scrHorizontalScroll setContentSize:CGSizeMake(999, 150)]; [scrHorizontalScroll setScrollEnabled:YES]; [HolderView addSubview:scrHorizontalScroll]; [scrHorizontalScroll addSubView:FirstView]; [scrHorizontalScroll addSubView:SecondView]; [HolderView addSubView: scrHorizontalScroll]; 

HolderView does not scroll horizontally, but happens, please help

Note. I have a mainView that adds this HolderView to its top according to the coordinates of the frame.

 [mainView addSubView:label].... [mainView addSubView:HolderView]; 

This is a complete structure.

+6
iphone uiscrollview
source share
2 answers

The scroll view will scroll only when its content is larger than its frame.

+15
source share
  FirstView = [[UIView alloc] initWithFrame:CGRectMake(60, 0, 100, 150)]; [FirstView setBackgroundColor:[UIColor clearColor]]; SecondView = [[UIView alloc] initWithFrame:CGRectMake(320+60, 0, 100, 150)]; [SecondView setBackgroundColor:[UIColor clearColor]]; HolderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 150)]; scrHorizontalScroll = [[UIScrollView alloc]initWithFrame:HolderView.frame]; [scrHorizontalScroll setBackgroundColor:[UIColor redColor]]; [scrHorizontalScroll setContentSize:CGSizeMake(999, 150)]; [scrHorizontalScroll setScrollEnabled:YES]; [HolderView addSubview:scrHorizontalScroll]; [scrHorizontalScroll addSubView:FirstView]; [scrHorizontalScroll addSubView:SecondView]; [HolderView addSubView: scrHorizontalScroll]; //set with of the scrHorizontalScroll as second view,increase content view size to x axis. 
+1
source share

All Articles