How to add marquee to a label

前端 未结 2 859
庸人自扰
庸人自扰 2020-12-29 00:27

I have a label at the top of my UIView.I am displaying some messages on it through array with the help of the timer.But now i want this messages to be displayed in MARQUEE s

2条回答
  •  不思量自难忘°
    2020-12-29 01:01

    Here's an idea:

    • Set clipsToBounds to true on the UIView that your UILabel is sitting in.
    • Then start a UIViewAnimations block (look in the docs for how to use it, its very simple)
      • Create a new label with its frame set to a position that is outside of the bounds of the enclosing UIView
      • set the previous label's position to somewhere to the left outside the bounds of the enclosing UIView
      • set the next label's position to where the previous label used to be.
    • commit the animations

    That should give you the sliding animation of one label moving off screen and a new label moving on screen.

    You'll have to play around with the animationDuration property and the precise positioning and sizing properties of the labels and views to get it just right, but it should be quite simple.

提交回复
热议问题