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