UINavigationBar name as music app

I am trying to create a title in a UINavigationBar that acts like a title in a Music app. That is, it has three lines, and the line will scroll if it is too long. The following code has several problems. 1) If the line is too long, it will be broken onto the next line. So if line 2 is too long, it overflows into line 3 and the third line is not displayed at all. Also, there is no way to change the line height and this is not the case for a UINavigationBar.

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 3;
label.font = [UIFont boldSystemFontOfSize: 12.0f];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
NSString *songData;
songData = [[songList objectAtIndex:currentIndex] artistName];
songData = [songData stringByAppendingString:@"\n"];
songData = [songData stringByAppendingString: [[songList objectAtIndex:currentIndex] songName]];
songData = [songData stringByAppendingString:@"\n"];
songData = [songData stringByAppendingString: [[songList objectAtIndex:currentIndex] albumName]];
label.text = songData;
self.navigationItem.titleView = label;

      

+3


source to share


3 answers


Have you tried MarqueeLabel ? It is very nice:)



MarqueeLabel is a subclass of UILabel that adds a scrolling effect when the label text grows out of the available width. You can also specify label scroll direction and speed / speed. All the standard UILabel properties (where it makes sense) are available in the MarqueeLabel and behave exactly like UILabel.

+4


source


You can create your own ticker for the same using time. Please refer to the source code for the same. it moves text from one direction to another.

https://github.com/MugunthKumar/MKTickerViewDemo



https://github.com/caydenliew/CLTickerView

0


source


I'm trying to do something like this, and while Mangesh answers half of the problem (scrolling), I'll try to help with the other half. To place multiple labels, you can create a new view and fill it with multiple labels to prevent problems between lines. There are many posts and tutorials out there that make customizing the navbar much more difficult than it needs to be if you just add something to the titleView. This is what I did:

  • Create a new view controller using xib.
  • Remove the default view specified in IB and replace it with a different view. Set its size using the size inspector. 128 x 33 is what the titleView will do. You will most likely want to set the browsing background to clear the color.
  • Drag some shortcuts into it (3 if you want it to look like an iOS Music app) and size / color respectively.
  • Set the new view as the file owner view.
  • Create any IBOutlets you need for the new shortcut and also attach them to the file owner in IB.
  • In the viewDidLoad of the view controller you want to work with the navigation controller with, initialize your custom view controller and set its view as navigationItem titleView:

    TitleViewController * customTitleVC = [[TitleViewController alloc] initWithNibName: nil bundle: nil]; self.navigationItem.titleView = customTitleVC.view;

If you are using Mangesh links, you will want to include the scroll view and include that in your custom view controller with the libraries it linked. The method I gave is verified to work with iOS 4.3 - 5.1. Hope that helps someone.

0


source







All Articles