如何制作字幕UILabel/UITextField/NSTextField [英] How to make marquee UILabel / UITextField / NSTextField

查看:97
本文介绍了如何制作字幕UILabel/UITextField/NSTextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Xcode中制作字幕UILabel.选框将从右向左滚动.

I need to make marquee UILabel in Xcode. The marquee will scroll from right to left.

我也尝试过CCScrollingLabelJHTickerView等.但是我找不到没有任何视图/数组/一些愚蠢的库和其他字幕的带有字幕的简单代码

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制作字幕? (UITextFieldNSTextField也可以).

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,NSTextFieldUILabel具有不同的方法.

*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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆