A powerful and easy to use marquee view. He moving here. I am best.
- 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.)
JXMarqueeType.left
:From right to left
JXMarqueeType.right
:From left to right
JXMarqueeType.reverse
:reverse
- XCode 9.0+
- Swift 5.0+ (greater or equal 0.0.8 version)
- Manually
- Download source code, drag JXMarqueeView.swift file into your project.
- Cocoapods
use_frameworks!
target '<Your Target Name>' do
pod 'JXMarqueeView'
end
- 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.
//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)
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.