Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hi this is a more general question on how to approach this. As you can see in the image below I have 4 textLabels in a stack view, and behind the stack view is a red UIVew.

When the UIView slides over the next text, I would like the text to change color whenever the view is over the text. I don't want an abrupt change, but rather a masking/sliding color effect, driven by the red UIView.

Currently its only changing colours once the transition is done.

How would you approach this?

enter image description here

on request the basic sliding code:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if isScrolling {
        let factor = (scrollView.contentOffset.x/UIScreen.main.bounds.width) * (margin.left/2)
        self.navigationBar.indicatorConstraint.constant = (scrollView.contentOffset.x / 4) - factor
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
301 views
Welcome To Ask or Share your Answers For Others

1 Answer

It is possible to achieve but it is not straight forward.

You would have to add white and black text UILabels. These labels contained on a view, for example the WhiteLabelsView and the BlackLabelsView. The red view should mask the WhiteLabelsView, and the BlackLabelsView should be behind them.

Your view should look like this (RedView is the top most view):

  • [ RedView ]
  • [ WhiteLabelsView ]
  • [ BlackLabelsView ]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...