[英]How to make marquee UILabel / UITextField / NSTextField
I need to make marquee UILabel
in Xcode. 我需要在Xcode中制作字幕
UILabel
。 The marquee will scroll from right to left. 选框将从右向左滚动。
I tried CCScrollingLabel
also JHTickerView
and others. 我尝试了
CCScrollingLabel
以及JHTickerView
等。 But i can not find simple code with marquee with out any views/arrays/some stupid libraries and others 但是我找不到没有任何视图/数组/一些愚蠢的库和其他字幕的简单代码
How to make marquee with UILabel
? 如何使用
UILabel
制作字幕? ( UITextField
and NSTextField
are OK too). (
UITextField
和NSTextField
也可以)。
You need NSTimer
and you need to invoke a method something as : 您需要
NSTimer
并且需要调用如下方法:
* This is for OSX, you can easily convert it into iOS, NSTextField
and UILabel
has different methods. * 这是针对OSX的,您可以轻松地将其转换为iOS,
NSTextField
和UILabel
具有不同的方法。
-(void)awakeFromNib{
self.myTimer=[NSTimer new];
self.fullString=@"This is a long string to be shown.";
[self.label setAlignment:NSRightTextAlignment];
}
-(void)scrollText:(id)parameter{
static NSInteger len;
[self.label setStringValue:[self.fullString substringWithRange:NSMakeRange(0, len++)]];
if (self.label.stringValue.length==self.fullString.length) {
[self.myTimer invalidate];
}
}
- (IBAction)buttonAction:(id)sender {
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.2f
target: self
selector:@selector(scrollText:)
userInfo: nil
repeats:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.