cbpowell / MarqueeLabel

A drop-in replacement for UILabel, which automatically adds a scrolling marquee effect when the label's text does not fit inside the specified frame
MIT License
4.19k stars 560 forks source link

Custom layer masks conflict with internal MarqueeLabel masking #214

Open snc001 opened 6 years ago

snc001 commented 6 years ago

Usage Details

Steps to Reproduce the Problem

  1. Clone the latest MarqueeLabel from Zip
  2. Import MarqueeLabel.swift manually into project
  3. Import QuartzCore.framework in build.phase link binary
  4. Used MarqueeLabel where is needed
  5. Clean project
  6. Run project on simulator - iOS 11.3; iPhone 8 Plus 5 error on line 1153 - Could not cast value of type 'CAShapeLayer' (0x111186cc0) to 'CAGradientLayer' (0x111187260) from MarqueeLabel.swift

Is there something that I have missed or have done wrong??

Any help is much appreciated :)

cbpowell commented 6 years ago

That's pretty weird, because line 1153 is where MarqueeLabel just returns the mask of the base view layer, and the only place the mask layer is set is at line 1029…where it is set as a CAGradientLayer.

Does your project code mask the MarqueeLabel in any way, by setting the aLabel.layer.mask property?

snc001 commented 6 years ago

Spot on! Yes I do for custom border rounding.

let nameLabelEdge = CAShapeLayer() nameLabelEdge.bounds = nameLabel.frame nameLabelEdge.position = nameLabel.center nameLabelEdge.path = UIBezierPath(roundedRect: nameLabel.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 9, height: 9)).cgPath nameLabel.layer.mask = nameLabelEdge

That is exactly how i have it at the moment

cbpowell commented 6 years ago

So yep that's the reason, your CAShapeLayer is replacing the CAGradientLayer that MarqueeLabel assigns to itself to handle the fading at the left and right edges.

There's probably a way for MarqueeLabel to mask itself without using the top layer mask so that it doesn't conflict, but I'll have to look into it. I think the quick and easy way for you to fix it right now would be to just put your MarqueeLabel instance inside a wrapper UIView and then mask that wrapper view.

snc001 commented 6 years ago

Yea that's exactly what i did as a work around =)