Pregunta

In iOS 7, when you scroll on iMessage, any messages that you have sent show up coloured with slightly different gradients depending on their scroll position. The gradient changes depending on where the cell is on the screen. If the cell is at the bottom, it will be a darker shade of blue, if the cell is at the top, it will be a lighter shade of blue, and any cells inbetween will have a shade of blue between the lightest (top cell) blue and darkest (bottom cell) blue.

Please can you tell me how I can dynamically change the background color of the cell on the fly depending on where it is in the view?

¿Fue útil?

Solución

You can create a gradient like the messages app using the CAGradientLayer.

Now, you can listen to the table view's scrolling using the UIScrollView delegate API. When scroll occurs, get all the visible cells of your table view, and calculate their frames in the superview (the table view) using convertPoint:toView: or convertRect:toView:. You can then make a small calculation of lighter and darker colors depending on the y coordinate.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top