快速标签的Marquee文本怎么样?

时间:2016-06-10 13:11:34

标签: swift marquee

我想在Swift中创建一个选框标签。我尝试了一些代码但却无法使用它。

我也可以用动画做到这一点,但我有重复它的问题。

我也试过了this

任何帮助将不胜感激。

4 个答案:

答案 0 :(得分:1)

使用可以加强其内容的标签非常简单。 只需在项目中添加MarqueeLabel pod即可。

<强>夫特:

pod 'MarqueeLabel/Swift'

然后选择要执行Marquee的标签,并在Identity Inspector中为其添加Custom Class MarqueeLabel。

就是这样。

这是在Label中添加选框的最简单方法。如果您想在标签内容的最后一个字符和第一个字符之间留出一些间距,那么在添加Custom Class MarqueeLabel之后:

步骤1:选择标签。

步骤2:转到属性检查器,然后将fadeLength属性值增加到您想要的值。将价值10应用于它是公平的。

如果您希望自定义更多内容,请将自定义类MarqueeLabel添加到Label中,然后在您的代码中取出该标签的插座,并按照您想要的方式对其进行自定义。

代码中该标签的出口应如下所示:

@IBOutlet var YOURLABELNAME: MarqueeLabel!

如果不是这样,那么首先将自定义类添加到标签,然后将其出口放在代码文件中。

答案 1 :(得分:0)

我不知道为什么我得到2 - ?!???

我试了很多东西。那不重要......

我在5分钟前找到了这个,这就是我使用动画而不是选框的答案。但在iOS选框上是一个棘手的问题!

here is the link that solved my repeating animation problem

我使用了这段代码而且它有效!也想帮助别人。

在ViewdidLoad上:

  if let aLabel = self.txtAmarFull {
        aLabel.pushTransition(3)

    }
身体上的

extension UIView {
func pushTransition(duration:CFTimeInterval) {
    let animation:CATransition = CATransition()
    animation.timingFunction = CAMediaTimingFunction(name:
        kCAMediaTimingFunctionEaseInEaseOut)
    animation.type = kCATransitionMoveIn
    animation.subtype = kCATransitionFromLeft
    animation.duration = duration
    animation.repeatCount = 99
    self.layer.addAnimation(animation, forKey: kCATransitionPush)
}

我的标签名称是:txtAmarfull

答案 2 :(得分:0)

我创造了更好的解决方案!

我将2种不同的方法结合在一起

这里的代码在swift中你可以做Marquee与终极重复,非常简单!只需在显示视图中放置标签。

 UIView.animateWithDuration(8.0, delay:0, options: [.Repeat], animations: {   
        self.YOURLABELNAME.frame = CGRectMake(self.YOURLABELNAME.frame.origin.x - 500, self.YOURLABELNAME.frame.origin.y - 0, self.YOURLABELNAME.frame.size.width, self.YOURLABELNAME.frame.size.height)
        }, completion: nil)

答案 3 :(得分:0)

检查此代码

var check = true
    var speed = 2
    var stopWidth = 200.0
override func viewDidLoad() {
        label.center.x = view.center.x // Place it in the center x of the view.
        label.center.x -= view.bounds.width // Place it on the left of the view with the width = the       
 Timer.scheduledTimer(timeInterval: TimeInterval(speed),
                             target: self,
                             selector: #selector(selectCityViewController.sliderAnimationTime),
                             userInfo: nil,
                             repeats: true)


    }

    @objc func sliderAnimationTime() {
        // do what should happen when timer triggers an event
        UIView.animate(withDuration: TimeInterval(speed), delay: 0, options: [.curveEaseOut], animations: {
            if self.check {
                self.check = false
                self.label.center.x -= self.view.bounds.width - CGFloat(self.stopWidth)
                self.view.layoutIfNeeded()
            }else{
                self.check = true
                self.label.center.x += self.view.bounds.width - CGFloat(self.stopWidth)
                self.view.layoutIfNeeded()
            }

        }, completion: nil)
    }
相关问题