Look at the effect chart as usual:
Ideas
Creates a view
parent control that acts as all content and adds it to the previous one label
as a carrier for displaying text
uilabel* Contentlabel = [[Uilabel alloc] init];
[Contentlabel SizeToFit];
Contentlabel.backgroundcolor = [Uicolor Clearcolor]; _contentlabel = Contentlabel; [Self AddSubview:self.contentLabel];
view
add a layer to the content, layer
mask
and set its scope to the view
entire bounds
, so that view
the excess content is not displayed
cashapelayer* Masklayer = [Cashapelayer layer];
Masklayer.path = [Uibezierpath bezierPathWithRect:self.bounds]. Cgpath;
Self.layer.mask = Masklayer;
To label
add an animation
cakeyframeanimation* keyframe = [cakeyframeanimation animation];
Keyframe.keypath = @ "transform.translation.x";
keyframe.values = @[@ (0), @ (-space), @ (0)];
Keyframe.repeatcount = Nsintegermax;
keyframe.duration = Self.speed * SELF.CONTENTLABEL.TEXT.LENGTH;
Keyframe.timingfunctions = @[[camediatimingfunction Functionwithname:kcamediatimingfunctioneaseineaseout], [ Camediatimingfunction functionwithcontrolpoints:0:0:0.5:0.5]];
Keyframe.delegate = self;
[Self.contentLabel.layer Addanimation:keyframe Forkey:nil];
How to use
Create
cfdynamiclabel* TestLabel = [[Cfdynamiclabel alloc] Initwithframe:cgrectmake (MB, 180,)];
Set rolling speed
testlabel.speed = 0.6;
[Self.view Addsubview:testlabel];
Set basic properties
Testlabel.text = @ "I don't want to say goodbye, don't say goodbye, grow more Lonely";
Testlabel.textcolor = [Uicolor yellowcolor];
Testlabel.font = [Uifont systemfontofsize:23];
Testlabel.backgroundcolor = [Uicolor Graycolor];
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.