[英]How can i use marquee in my Application?
I wrote the code for marquee shown below---我编写了如下所示的选框代码---
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
//NSTimer *timer=[[NSTimer alloc] initWithFireDate:nil interval:.5 target:self selector:@selector(marqueDisplay) userInfo:nil repeats:YES];
[NSTimer scheduledTimerWithTimeInterval:7.0
target:self
selector:@selector(marqueDisplay)
userInfo:nil
repeats:YES];
}
-(void)marqueDisplay
{
NSString *theMessage = @"Hello, my name is Enigo Montoya. You killed my father, prepare to die";
NSUInteger length = [theMessage length];
NSLog(@"%d",length);
if (length>69) {
messageSize = [theMessage sizeWithFont:[UIFont systemFontOfSize:14.0]];
messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, messageSize.width, 19)]; //x,y,width,height
[messageView setClipsToBounds:YES]; // With This you prevent the animation to be drawn outside the bounds.
[self.view addSubview:messageView];
lblTime = [[UILabel alloc] initWithFrame:CGRectMake(-400, 0, messageSize.width, 19)]; //x,y,width,height
[lblTime setBackgroundColor:[UIColor darkGrayColor]];
lblTime.font = [UIFont systemFontOfSize:14];
[lblTime setText:theMessage];
[lblTime setTextAlignment:UITextAlignmentLeft];
//lblTime.frame = CGRectMake(0, 0, messageSize.width, 19); //x,y,width,height
[messageView addSubview:lblTime];
float duration = messageSize.width / 60; // This determines the speed of the moving text.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:messageView cache:YES];
lblTime.frame = CGRectMake(messageSize.width, 0, messageSize.width, 19); //x,y,width,height
[UIView commitAnimations];
}
}
this works but this is not satisfying my need... Actually the text is not moving in loop form, i want that if string length > 60 then marquee start and appended the string.这可行,但这不能满足我的需要...实际上文本并没有以循环形式移动,我希望如果字符串长度> 60,则选取框开始并附加字符串。
Plz help me to solve this problem.. Thanks in advance.请帮我解决这个问题..提前谢谢。
Here you go https://github.com/jeffhodnett/JHTickerView你在这里 go https://github.com/jeffhodnett/JHTickerView
here is another https://github.com/ConceitedCode/CCScrollingLabel这是另一个https://github.com/ConceitedCode/CCScrollingLabel
I hope your problem will be solved.我希望你的问题能得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.