0

I have a horizontal scrollview like below with V as an overlay and it acts like a pointer:

   V
 [ 0 ] , [ 1 ] , [ 2 ] , [ 3 ] , [ 4 ] , [ 5 ] 
   ^

When I scroll, I would like to print the value or index that is in the current pointer. Eg. scroll until [2] and it will print "2".

   V
 [ 2 ] , [ 3 ] , [ 4 ] , [ 5 ] 
   ^

Could you guide me on how to achieve this?

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • SwiftUI is pretty limited in terms of reading a scroll position (despite the questionably-named `ScrollViewReader`, which really does the opposite). This may be a problem better-solved with UIKit. – jnpdx Mar 30 '22 at 02:09

1 Answers1

0

I ended up using offset for this. Set a fixed width for a column, then we can calculate the offset for each column.