gpt4 book ai didi

objective-c - 如何制作字幕 UILabel/UITextField/NSTextField

转载 作者:技术小花猫 更新时间:2023-10-29 11:08:52 35 4
gpt4 key购买 nike

我需要在 Xcode 中制作选取框 UILabel。选取框将从右向左滚动。

我尝试了 CCScrollingLabel 也尝试了 JHTickerView 和其他。但是我找不到没有任何 View /数组/一些愚蠢的库和其他的带有选取框的简单代码

如何使用UILabel制作跑马灯? (UITextFieldNSTextField 也可以)。

最佳答案

你需要 NSTimer 并且你需要调用一个方法:

*这是针对 OSX 的,你可以很容易地将它转换成 iOS,NSTextFieldUILabel 有不同的方法。

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

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com