Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android like view pager with tabs on iOS

I would like to know what would be the best way to implement an android like view pager with tabs on iOS like the one found on the FIFA world cup app Reference Image

The various approaches that I could think of were:

  1. Customised UITabBarController with a swipe and pan gesture- I tried this and the swipe experience was not as fluid as the FIFA app. It was sluggish like the new Skype app (Think they are using this approach).
  2. Page View Controller- I tried this too but ran into some strange issues. Did not try too much after that.
  3. Collection View Controller with horizontal paging- This seemed like the best approach to me, but I am not sure about memory management.

My current implementation- I have three tab bar entries as of now. I have separate view controllers for each of them. Here is the way I implemented it using horizontal paging collection view:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

NSInteger indexNumber = indexPath.row;
UICollectionViewCell *cell;

switch (indexNumber) {
    case 0:
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell1" forIndexPath:indexPath];
        [cell.contentView addSubview:self.firstViewControllerObject.view];
        break;
    case 1:
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell2" forIndexPath:indexPath];
        [cell.contentView addSubview:self.secondViewControllerObject.view];
        break;
    case 2:
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell3" forIndexPath:indexPath];
        [cell.contentView addSubview:self.thirdViewControllerObject.view];
        break;

    default:
        break;
}

return cell;
}

I could not figure out a way to manage cells better thus I made different entities. How can I do it better with this approach or if this approach is not good what should I use?

like image 668
vin25 Avatar asked Jun 23 '14 08:06

vin25


People also ask

How do I add tabs to Android app?

Tabs are created using newTab() method of TabLayout class. The title and icon of Tabs are set through setText(int) and setIcon(int) methods of TabListener interface respectively. Tabs of layout are attached over TabLayout using the method addTab(Tab) method.

Why use ViewPager?

ViewPager in Android allows the user to flip left and right through pages of data. In our android ViewPager application we'll implement a ViewPager that swipes through three views with different images and texts.


1 Answers

Actually for iOS, implement the native component like segmented control would be a better approach rather than trying to implement like what native android has to offer.

But if you really wanna try a viewpager like android, i think you can try using this library here. I tried implemented it myself and looks great. Hope it helps.

like image 126
Edy Avatar answered Sep 20 '22 10:09

Edy