我需要在 Xcode 中制作选取框 UILabel
。选取框将从右向左滚动。
我尝试了 CCScrollingLabel
也尝试了 JHTickerView
和其他。但是我找不到没有任何 View /数组/一些愚蠢的库和其他的带有选取框的简单代码
如何使用UILabel
制作跑马灯? (UITextField
和 NSTextField
也可以)。
最佳答案
你需要 NSTimer
并且你需要调用一个方法:
*这是针对 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];
}
关于objective-c - 如何制作字幕 UILabel/UITextField/NSTextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11255988/