UINavigationBar TitleView z napisami
Chcę titleView wewnątrz mojego UINavigationBar, który ma dwie linie tekstu zamiast tylko jednego
Moja obecna implementacja działa dobrze, gdy mam przycisk „Wstecz” i przycisk „Edytuj”, ponieważ wygląda prawie wyśrodkowany. Problem polega na tym, że mam tylko jeden z przycisków. Wygląda to naprawdę dziwnie i źle, ponieważ widok skupia się na dostępnej przestrzeni.
UINavigationBar z lewym i prawym przyciskiem
UINavigationBar z jednym przyciskiem
To jest moja obecna implementacja:
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;