UINavigationBar TitleView с субтитрами

Я хочу titleView внутри моего UINavigationBar, который имеет две строки текста вместо одной

Моя текущая реализация работает хорошо, когда у меня есть "Назад»-Кнопка "Редактировать" Кнопка, потому что это выглядит почти по центру. Проблема в том, когда у меня есть только одна из кнопок. Это выглядит действительно странно и неправильно, потому что представление центрируется на доступном пространстве.

UINavigationBar с левой и правой кнопкой

UINavigationBar только с одной кнопкой

Это моя текущая реализация:

CGRect frame = self.navigationController.navigationBar.frame;

UIView *twoLineTitleView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetWidth(frame), 0, CGRectGetWidth(frame), CGRectGetHeight(frame))];

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 8, CGRectGetWidth(frame), 14)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.text = self.title;
[twoLineTitleView addSubview:titleLabel];

UILabel *subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 23, CGRectGetWidth(frame), 14)];
subTitleLabel.backgroundColor = [UIColor clearColor];
subTitleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
subTitleLabel.textAlignment = UITextAlignmentCenter;
subTitleLabel.text = self.subTitle;
[twoLineTitleView addSubview:subTitleLabel];

self.navigationItem.titleView = twoLineTitleView;

Ответы на вопрос(9)

Ваш ответ на вопрос