How to Move text on navigation bar

后端 未结 4 1984
生来不讨喜
生来不讨喜 2021-01-16 03:52

Hi I have to move the text on navigation bar..I don\'t have any idea about scrolling text. Is anybody have idea about this please let me know.

Thanks

相关标签:
4条回答
  • 2021-01-16 04:27

    Swift 5 approach with MarqueeLabel:

        let title = MarqueeLabel(frame: CGRect.zero, duration: 20, fadeLength: 10)
        title.textAlignment = .center
        title.textColor = .white
        title.text = header
    
        navigationController?.navigationBar.topItem?.titleView = title
    
    0 讨论(0)
  • 2021-01-16 04:38

    I think you want to move label text exactly same like in iphone music player application. If yes then do the following.

    1`. Download Marquee Label files from this link 'https://github.com/cbpowell/MarqueeLabel'.`
    
    
    2.   - (void)addMovingLabelText { 
                MarqueeLabel *_lectureName = [[MarqueeLabel alloc] initWithFrame:CGRectMake(0,20,200, 20) duration:5.0 andFadeLength:10.0f];
                [_lectureName setTextAlignment:NSTextAlignmentCenter];
                [_lectureName setBackgroundColor:[UIColor clearColor]];
                [_lectureName setText:@"I am a moving Label in iphone Application"];
                _lectureName.adjustsFontSizeToFitWidth=NO;
                [_lectureName setAnimationCurve:UIViewAnimationOptionCurveEaseIn];
                [self.navigationItem setTitleView:_lectureName];
    }
    
    3. call addMovingLabelText from viewDidLoad
    
    0 讨论(0)
  • 2021-01-16 04:46

    Well, navbars can be customized with your own titleView, so all you need to do is create a view with the scrolling text inside. Because there is no component to achieve this effect in the SDK, you have to look for one in open-sourced libraries or create your own. I never used it, but take a look to this one UIScrollingLabel

    0 讨论(0)
  • 2021-01-16 04:49

    ADD this files in to your project and import it in to your class then add the following command in your view did load.I hope You are using a navigation based template for your application.

    http://blog.stormyprods.com/2009/10/simple-scrolling-uilabel-for-iphone.html

    and then in viewdidload

    AutoScrollLabel *autoScrollLabel=[[AutoScrollLabel alloc] initWithFrame:CGRectMake(10, 15, 320, 16)];
    autoScrollLabel.text = @"Hi Mom!  How are you?  I really ought to write more often.";
    autoScrollLabel.textColor = [UIColor whiteColor];
    //self.title = @"Resources";
    //self.title = @"%@"autoScrollLabel;
    [self.navigationController.navigationBar addSubview:autoScrollLabel];
    
    0 讨论(0)
提交回复
热议问题