xmartlabs / XLPagerTabStrip

Android PagerTabStrip for iOS.
MIT License
6.98k stars 1.33k forks source link

How can i implement this Tab not at the top of the screen but at the middle of the screen? #386

Open 01sunjon opened 7 years ago

01sunjon commented 7 years ago
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  let child_1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "child1")
  let child_2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "child2")
  return [child_1, child_2]
}

This lets me to add the tabs at the Upper of the viewcontroller. But i want them to be at the middle of the screen. how can i achieve this..??

fedeojeda95 commented 7 years ago

Hi @01sunjon,

Are you using storyboard or creating the UI by code? If you are using storyboard then its really simple, since you could simply set the constrains for the buttonBarView where you want, in this case, to the middle.

If you are setting the UI programatically, then you should set the frame of buttonBarView programatically after viewDidLoad, or programatically add constraints to it.

Hope it helps! Regards,

vansh1sh commented 7 years ago

Hi @01sunjon ,

It doesn't work by any of the method.

taichi-jp commented 7 years ago

@01sunjon @vansh1sh @fedeojeda95 I met the same problem. Setting the constraints in storyboard doesn't work and the PagerTab always comes at the top of screen. How can I solve it ?

vansh1sh commented 7 years ago

@taichikoumoto Try to set constraints properly, it did work for me after then.

zanesc commented 7 years ago

Also had this issue but I figured it out as well. Along with the constraints, you have to ensure that you have the delegates set correctly.

Connect outlets and add layout constraints

We strongly recommend to use IB to set up our page controller views.

Drag into the storyboard a UIViewController and set up its class with your pager controller (MyPagerTabStripName). Drag a UIScrollView into your view controller view and connect PagerTabStripViewController containerView outlet with the scroll view.

Depending on which type of paging view controller you are working with you may have to connect more outlets.

For BarPagerTabStripViewController we should connect barView outlet. barView type is UIView. ButtonBarPagerTabStripViewController requires us to connect buttonBarView outlet. buttonBarView type is ButtonBarView which extends from UICollectionView. SegmentedPagerTabStripViewController has a segmentedControl outlet, if the outlet is not connected the library try to set up the navigationItem titleView property using a UISegmentedControl. TwitterPagerTabStripViewController doesn't require us to connect any additional outlet.