UINavigationBarに2行のタイトルを表示


UIViewContorollerのnavigationItem.titleViewに、タイトルを2行表示するためのUILabelを設定してから、UINavigationControllerにpushすれば良い。

以下のソースコードをコピーすれば、ラベルのサイズや文字のスタイルを調整する手間が省けます。

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 2;
label.font = [UIFont boldSystemFontOfSize: 14.0f];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = @"タイトル\nサブタイトル";

controller.navigationItem.titleView = label;

スクリーンショット

タイトルを2行に
タイトルを2行に

参考
http://stackoverflow.com/questions/2422383/uinavigationbar-multi-line-title

Comments

comments

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です