UINavigationBar TitleView mit Untertitel
Ich möchte eine titleView in meiner UINavigationBar, die zwei Textzeilen anstelle von nur einer enthält
Meine aktuelle Implementierung funktioniert gut, wenn ich einen "Zurück" -Button und einen "Bearbeiten" -Button habe, da er fast zentriert aussieht. Das Problem ist, wenn ich nur einen der Buttons habe. Es sieht wirklich komisch und falsch aus, weil sich die Ansicht auf den verfügbaren Platz konzentriert.
UINavigationBar mit linker und rechter Taste
UINavigationBar mit nur einer Schaltfläche
Dies ist meine aktuelle Implementierung:
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;