I am using XLPagerTabStrip
for getting TabBar
with ViewPager
type behaviour like Android. I have configured as per their github repo documentation guideline but on my case it is having a peculiar behaviour at my simulator iPhone11 Pro max and real device iPhone 6+. The tab bar is scrolling a bit on selecting last tab though there is no need of scroll. And in iPhone 6, It is showing full screen for single tab. I am attaching code and screenshot. Any kind of help is appreciable. Thanks in advance
Here is my code
class TalkRoomPagerViewController: BaseButtonBarPagerTabStripViewController<PagerTabCell>, StoryboardBased, ViewModelBased {
var viewModel: TalkRoomPagerViewModel!
private let bag = DisposeBag()
private var allTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .all,
filteredTalkroomWithPreferenceLists: self.viewModel.allTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate,
pagerTabIndex: self.viewModel.pagerTabIndexSubject.asObserver())
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
private var siteTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .site,
filteredTalkroomWithPreferenceLists: self.viewModel.siteTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate)
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
private var companyTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .company,
filteredTalkroomWithPreferenceLists: self.viewModel.companyTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate)
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
private var groupTalkRoom: TalkRoomListViewController {
let viewModel = TalkRoomListViewModel(type: .group,
filteredTalkroomWithPreferenceLists: self.viewModel.groupTalkRoomWithPreferenceLists,
requestPreferenceUpdate: self.viewModel.requestPreferenceUpdate)
let services = TalkroomListServices(chatRoomNetwork: ChatRoomNetwork())
let viewController = TalkRoomListViewController.instantiate(withViewModel: viewModel, andServices: services)
return viewController
}
public var steppers: [Stepper] {
return [viewModel, allTalkRoom.viewModel, siteTalkRoom.viewModel, companyTalkRoom.viewModel, groupTalkRoom.viewModel]
}
override func viewDidLoad() {
self.prepareUI()
self.configureNavigationBar()
super.viewDidLoad()
bindViewModel()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.requestTalkRoomList.onNext(())
viewModel.requestPreferenceList.onNext(())
viewModel.locationFilter.accept(PersistenceManager.shared.savedFilterLocation)
}
func bindViewModel() {
viewModel.pagerTabIndexSubject.subscribe(onNext: { (index) in
self.moveToViewController(at: index, animated: true)
})
.disposed(by: bag)
viewModel.preferenceUpdateResponse.subscribe(onNext: { [weak self] _ in
self?.viewModel.requestTalkRoomList.onNext(())
self?.viewModel.requestPreferenceList.onNext(())
})
.disposed(by: bag)
}
private func prepareUI() {
self.title = "トークルーム一覧"
buttonBarView.isScrollEnabled = false
buttonBarItemSpec = ButtonBarItemSpec.nibFile(nibName: "PagerTabCell", bundle: Bundle(for: PagerTabCell.self)) { _ in
return self.view.frame.width/4
}
settings.style.buttonBarBackgroundColor = .white
settings.style.buttonBarItemBackgroundColor = .white
settings.style.selectedBarBackgroundColor = Asset.duskBlue.color
settings.style.selectedBarHeight = 2.0
settings.style.buttonBarMinimumLineSpacing = 0
settings.style.buttonBarItemTitleColor = .black
settings.style.buttonBarLeftContentInset = 0
settings.style.buttonBarRightContentInset = 0
changeCurrentIndexProgressive = { (oldCell: PagerTabCell?, newCell: PagerTabCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
guard changeCurrentIndex == true else { return }
oldCell?.titleLabel.textColor = .black
newCell?.titleLabel.textColor = Asset.duskBlue.color
}
}
private func configureNavigationBar() {
self.addBarItem(position: .left, title: "編集", target: self, action: #selector(editButtonTapped))
self.addBarItem(position: .right, image: Asset.iconPlus.image, target: self, action: #selector(addButtonTapped))
}
@objc private func editButtonTapped() {
}
@objc private func addButtonTapped() {
self.viewModel.navigateToCreateTalkRoom()
}
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
return [allTalkRoom, siteTalkRoom, companyTalkRoom, groupTalkRoom ]
}
override func configure(cell: PagerTabCell, for indicatorInfo: IndicatorInfo) {
cell.iconImageView.image = indicatorInfo.image?.withRenderingMode(.alwaysOriginal)
cell.titleLabel.text = indicatorInfo.title
}
}
I don't know what is an issue in your code but I had used XLPagerTabStrip & getting the same kind of problem. They have very little documentation. I download their demo example code from Github. I just copy-paste their view controller From storyboard & code. After that, I modify it as per my requirements.
If you are using Xcode 11 or above then check your App’s Light Mode & Dark-mode capability. If your app is fully in Light mode then provide dark mode support. I hope this may be helpful to you.