如何制作字幕UILabel/UITextField/NSTextField [英] How to make marquee UILabel / UITextField / NSTextField
问题描述
我需要在Xcode中制作字幕UILabel
.选框将从右向左滚动.
I need to make marquee UILabel
in Xcode. The marquee will scroll from right to left.
我也尝试过CCScrollingLabel
和JHTickerView
等.但是我找不到没有任何视图/数组/一些愚蠢的库和其他字幕的带有字幕的简单代码
I tried CCScrollingLabel
also JHTickerView
and others. But i can not find simple code with marquee with out any views/arrays/some stupid libraries and others
如何使用UILabel
制作字幕? (UITextField
和NSTextField
也可以).
How to make marquee with UILabel
? (UITextField
and NSTextField
are OK too).
推荐答案
您需要NSTimer
并且需要调用一个方法,如:
You need NSTimer
and you need to invoke a method something as :
* 这是用于OSX的,您可以轻松地将其转换为iOS,NSTextField
和UILabel
具有不同的方法.
*This is for OSX, you can easily convert it into iOS, NSTextField
and UILabel
has different methods.
-(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];
}
这篇关于如何制作字幕UILabel/UITextField/NSTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!