我試圖在UINavigationBar中創建一個標題,就像音樂應用程序中的標題一樣。也就是說,它有三條線,如果線太長,一條線會滾動。以下代碼有幾個問題。 1)如果一條線太長,它將打破下一條線。所以如果第2行太長,它會溢出到第3行,第3行根本沒有顯示。此外,沒有辦法改變行高,這不適合UINavigationBar。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;