IOS dynamically displays all text on a fixed label _ios

Source: Internet
Author: User

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];

viewadd 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.