Skip to content

pujiaxin33/JXMarqueeView

Repository files navigation

JXMarqueeView

languages platform cocoapods

A powerful and easy to use marquee view.

中文博客介绍

Features

  • Automatically start marquee. (When the content beyond size, marquee start automatically.)
  • Support UIView an its subclasses. (More than just UILabel, you can customize the view to turn on the marquee effect.)

Preview

JXMarqueeType.left:From right to left

left.gif

JXMarqueeType.right:From left to right

right.gif

JXMarqueeType.reverse:reverse

reverse.gif

Requirements

  • XCode 9.0+
  • Swift 5.0+ (greater or equal 0.0.8 version)

Installation

  1. Manually
    • Download source code, drag JXMarqueeView.swift file into your project.
  2. Cocoapods
use_frameworks!
target '<Your Target Name>' do
    pod 'JXMarqueeView'
end

Usage

  • contentMargin

The interval between two views,default is 12.

  • frameInterval

Assiagned to CADisplayLink frameInterval property,default is 1.

  • pointsPerFrame

How many points each time for callback of CADisplayLink.The bigger the faster.

  • contentView

The view your need to marquee.

  • SizeToFit

When you customize complex content view, you need override func sizeThatFits(_ size: CGSize) -> CGSize,and return you correct content size.

Use case

//text
let label = UILabel()
label.textColor = UIColor.red
label.font = UIFont.systemFont(ofSize: 30, weight: .medium)
label.text = "abcdefghijklmnopqrstuvwxyz"

marqueeView.contentView = label
marqueeView.contentMargin = 50
marqueeView.marqueeType = .left
self.view.addSubview(marqueeView)

//picture
let imageView = UIImageView(image: UIImage(named: "haizeiwang.jpeg"))
imageView.contentMode = .scaleAspectFill

marqueeView.contentView = imageView
marqueeView.marqueeType = .reverse
self.view.addSubview(marqueeView)

Customize

The default implementation of contentView's copy using code:

let archivedData = NSKeyedArchiver.archivedData(withRootObject: self)
let copyView = NSKeyedUnarchiver.unarchiveObject(with: archivedData) as! UIView

But if the view has cornerRadius、shadow, the copyView will lose it. So you should implement protocol JXMarqueeViewCopyable function func copyMarqueeView() -> UIView. Just return a new instance UIView. Just checkout CustomCopyView.swift in example.

Picture case preview

picture.gif

Custom case preview

poetry.gif

About

A powerful and easy to use marquee view.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published