Using Uilabel to achieve text scrolling (marquee) effect

Source: Internet
Author: User

- (void) viewdidload {[Super viewdidload]; //Data SourceSelf.messagearray =[Nsarray arraywithobjects:@"1",                         @"2",                         @"3", nil]; Self.msgcount=0;//Show from the beginning of the first article}
-(void) viewdidappear: (BOOL) animated {    // play first and add timer to set switch interval time     [self msgchange];    [Nstimer scheduledtimerwithtimeinterval: 5.0f target:self selector: @selector (msgchange) Userinfo:nil repeats:yes];}
- (void) Msgchange {if(Self.msgcount <self.messageArray.count) {Self.scrollLabel.text=[Self.messagearray ObjectAtIndex:self.msgCount]; Self.msgcount++; } Else{Self.scrollLabel.text=@"No message";//Delete here can be changed to loop scroll play} [Self.scrolllabel SizeToFit]; CGRect Frame=Self.scrollLabel.frame; Frame.origin.x=[UIScreen mainscreen].bounds.size.width; Self.scrollLabel.frame=frame; [UIView beginanimations:@"scrolllabeltest"Context:null]; [UIView setanimationduration:5.0f];    [UIView Setanimationcurve:uiviewanimationcurvelinear];    [UIView setanimationdelegate:self];    [UIView Setanimationrepeatautoreverses:no]; [UIView Setanimationrepeatcount:0]; Frame=Self.scrollLabel.frame; Frame.origin.x= -Frame.size.width; Self.scrollLabel.frame=frame; [UIView commitanimations];}

Using Uilabel to achieve text scrolling (marquee) effect

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.