         
         //        print("didScrollToPageAtIndex: \(index)")
         
-        gradient?.gradientOffset = CGFloat(index) / CGFloat((pageboyViewController.pageCount ?? 1) - 1)
+        gradient?.gradientOffset = gradientOffset(for: CGFloat(index))
         statusView.currentIndex = index
         updateBarButtonsForCurrentIndex()
     }

        //        print("didScrollToPosition: \(position)")
        
        let relativePosition = navigationOrientation == .vertical ? position.y : position.x
        gradient?.gradientOffset = relativePosition / CGFloat((pageboyViewController.pageCount ?? 1) - 1)
        statusView.currentPosition = relativePosition
        
        updateBarButtonsForCurrentIndex()

        return BarItem(title: "Page No. \(index + 1)")
    }
}

private extension TabPageViewController {
    
    private func gradientOffset(for position: CGFloat) -> CGFloat {
        return position / CGFloat((self.pageCount ?? 1) - 1)
    }
}
