简体   繁体   English

如何制作字幕UILabel / UITextField / NSTextField

[英]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). UITextFieldNSTextField也可以)。

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, 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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM