It looks like you're new here. If you want to get involved, click one of these buttons!
- (void)viewDidLoad {
arr = [[NSMutableArray alloc] initWithObjects:@\"Test1\",@\"Test2\",@\"Test3\",@\"Test4\",@\"Test5\",nil];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"bg_content_slide.png\"]];
img.frame = CGRectMake(0, 20, 320, 85);
img.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:img];
[self setScrollButtons];
[super viewDidLoad];
}
- (void) setScrollButtons
{
tagScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 320, 44)];
tagScrollView.backgroundColor = [UIColor clearColor];
[tagScrollView setShowsHorizontalScrollIndicator:NO];
[tagScrollView setShowsVerticalScrollIndicator:NO];
[tagScrollView setCanCancelContentTouches:NO];
tagScrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
tagScrollView.clipsToBounds = YES;
tagScrollView.scrollEnabled = YES;
tagScrollView.pagingEnabled = YES;
tagScrollView.bounces = YES;
tagScrollView.delegate = self;
tagScrollView.tag = 2;
pageControl.numberOfPages = [arr count];
pageControl.currentPage = 0;
[pageControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged];
int xaxis = 0;
for (int i = 0; i < [arr count]; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(xaxis+80, 0, 160, 44);
//btn.titleLabel.text = [NSString stringWithFormat:@\"%@\",[arr objectAtIndex:i]];
[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
NSLog(@\"%@\", btn.titleLabel.text);
xaxis += btn.frame.size.width + 40;
[tagScrollView addSubview:btn];
}
[tagScrollView setContentSize:CGSizeMake([arr count] * 220, tagScrollView.frame.size.height)];
[self.view addSubview:tagScrollView];
}
- (void) pageTurn: (UIPageControl *) aPageControl
{
whichPage = aPageControl.currentPage;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
tagScrollView.contentOffset = CGPointMake(200.0f * whichPage, 0.0f);
[UIView commitAnimations];
}
- (void) scrollViewDidScroll: (UIScrollView *) scrollView
{
CGPoint offset = scrollView.contentOffset;
NSLog(@\"offset is %@\",NSStringFromCGPoint(offset));
CGFloat pageWidth = floor(scrollView.contentSize.width/pageControl.numberOfPages) ;
//pageWidth = 190;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
NSLog(@\"Page is : %d\",page);
pageControl.currentPage = page;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate // called on finger up if user dragged. decelerate is true if it will continue moving afterwards
{
CGFloat pageWidth = floor((scrollView.contentSize.width-220)/pageControl.numberOfPages) ;
//pageWidth = 190;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth)+1;
NSLog(@\"Page is : %d\",page);
pageControl.currentPage = page;
}