vin25
vin25

Reputation: 346

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?

Upvotes: 9

Views: 9408

Answers (1)

Edy
Edy

Reputation: 245

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.

Upvotes: 4

Related Questions