Skip to content

Commit 5d78fbe

Browse files
committed
Calculate number of required replications for forced continuous scrolling
1 parent 9ce2ef6 commit 5d78fbe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/MarqueeLabel.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,10 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {
669669
sublabel.frame = homeLabelFrame
670670

671671
// Configure replication
672-
repliLayer?.instanceCount = 2
672+
// Determine replication count required
673+
let fitFactor: CGFloat = bounds.size.width/(expectedLabelSize.width + leadingBuffer)
674+
let repliCount = 1 + Int(ceil(fitFactor))
675+
repliLayer?.instanceCount = repliCount
673676
repliLayer?.instanceTransform = CATransform3DMakeTranslation(-awayOffset, 0.0, 0.0)
674677

675678
case .leftRight, .left, .rightLeft, .right:

0 commit comments

Comments
 (0)