【问题标题】:how to implement marquee label in IOS using swift如何使用swift在IOS中实现选框标签
【发布时间】:2015-10-08 05:06:38
【问题描述】:

如何在 iOS 中实现MarqueeLabel。我在 Objective-C 中找到了示例,但我使用的是 Swift。

【问题讨论】:

标签: ios swift uilabel marquee


【解决方案1】:

用于在您的项目https://github.com/cbpowell/MarqueeLabel 中快速添加下面的类

为此,首先添加 pod:pod 'MarqueeLabel'。

并在您的项目中执行pod update。

然后在您的工作文件中导入 pod: import MarqueeLabel

创建一个标签并将自定义类设置为故事板中的MarqueeLabel。 那么:

@IBOutlet weak var marqueeLabel:MarqueeLabel!

在 ViewDidLoad 中添加:

marqueeLabel.type = .Continuous
marqueeLabel.scrollDuration = 5.0
marqueeLabel.animationCurve = .EaseInOut
marqueeLabel.fadeLength = 10.0
marqueeLabel.leadingBuffer = 30.0
marqueeLabel.trailingBuffer = 20.0

【讨论】:

    【解决方案2】:

    使用MarqueeLabel,非常容易使用和实现。

    如果您使用的是 Pod,那么您可以集成并尝试示例代码:

    目标-C:

    pod 'MarqueeLabel'
    
    MarqueeLabel *lengthyLabel = [[MarqueeLabel alloc] initWithFrame:aFrame duration:8.0 andFadeLength:10.0f];
    

    斯威夫特:

    pod 'MarqueeLabel/Swift'
    
    var lengthyLabel = MarqueeLabel.init(frame: aFrame, duration: 8.0, fadeLength: 10.0)
    


    另一种使用 Web 视图的解决方案:

    String marquee = "<html><body><marquee>This is sample marquee</marquee></body></html>"
    webview.loadData(marquee, "text/html", null);
    


    这是结果:

    【讨论】:

      【解决方案3】:

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

      斯威夫特:

      pod 'MarqueeLabel/Swift'
      

      然后选择您希望在其上执行 Marquee 的标签,并在 Identity Inspector 中将自定义类 MarqueeLabel 添加到它。

      就是这样。

      这是在标签中添加选取框的最简单方法。添加自定义类 MarqueeLabel 后,如果您希望标签内容的最后一个字符和第一个字符之间有一些间距,则:

      第 1 步:选择标签。

      第 2 步:转到 Attributes Inspector,然后将 fadeLength 属性值增加到您想要的程度。对其应用值 10 就足够公平了。

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

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

      @IBOutlet var YOURLABELNAME: MarqueeLabel!
      

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

      【讨论】:

        【解决方案4】:

        下载以下链接github Marquee label Demo:

        https://github.com/cbpowell/MarqueeLabel-Swift

        然后

        按照以下步骤操作:

        1. 下载上面的github项目

        2. 从类中复制 Marqueelabel.swift 文件

        3. 将 Marqueelabel.swift 文件粘贴到您的项目中

        4. 将您的任何 UILabel 设为 MarqueeLabel 类型

          例如:@IBOutlet 弱变量 demoLabel1:MarqueeLabel!

        5. 运行你的项目

        【讨论】:

        • 我修复了错误是swift 1和2之间差异的错误,感谢您的帮助。
        【解决方案5】:

        【讨论】:

        • 此库已弃用。
        【解决方案6】:

        在 Apple tvOS 中使用 MarqueeLabel 设置这样的速度

        https://github.com/cbpowell/MarqueeLabel

        之前在我的项目中设置的速度

        videoTitleLabel.speed = .duration(25.0)

        现在我把 25.0 改成了 10

        videoTitleLabel.speed = .duration(10)

        现在它移动位速度

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-07-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-10-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多