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
The various approaches that I could think of were:
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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With