- (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