How to make marquee UILabel / UITextField / NSTextField

前端 未结 1 398
自闭症患者
自闭症患者 2020-12-14 11:41

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

I tried CCScrollingLabel also JHTickerView

相关标签:
1条回答
  • 2020-12-14 12:20

    You need NSTimer and you need to invoke a method something as :

    *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];
    }
    
    0 讨论(0)
提交回复
热议问题