2

I'm making a custom picker control and I'm facing a problem - I need to animate uilabels text color change partially.

Here is the example:
enter image description here

This is a default view of picker. When I click left or right side, the white selector will slide to that side. But since the label text color is white, I need to change the color partially, so if my white selector is halfway through the label, the part of the text in label that is on gray background should be white color and the part that selector covers should be gray color.

I would be grateful to any suggestion.

Dvole
  • 5,725
  • 10
  • 54
  • 87

2 Answers2

2

You could do this by having your white selector act as a mask. Duplicate your three labels -- one set for white, the other for grey -- and position them overlapping on each other. Add the three grey ones as subviews of the white selector and cause the white selector to clipsToBounds. When you animate the selector, animate the subview labels in the opposite direction at the same rate and they will appear to stay in place but become revealed as your white bar moves.

Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51
1

You could use NSAtributedText. When moving the slider you can see how much of the slider is overlaping the label, convert that distance in text range and set the gray color for the text coresponding to te textrange you found using NSAttributedText properties.

Adi Pop
  • 226
  • 2
  • 10