我正在尝试在 UINavigationBar 中创建一个标题,该标题类似于音乐应用程序中的标题。也就是说,它有三行,如果一行太长,就会滚动。下面的代码有几个问题。1)如果一行太长,它将中断到下一行。因此,如果第 2 行太长,它会溢出到第 3 行,并且根本不会显示第三行。此外,无法更改行高,这不适合 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;