UINavigationBar TitleView con subtítulo
Quiero un titleView dentro de mi barra de UINavigation que tiene dos líneas de texto en lugar de una sola
Mi implementación actual funciona bien cuando tengo un botón "Atrás" y un botón "Editar" porque parece casi centrado. El problema es cuando solo tengo uno de los botones. Parece realmente extraño e incorrecto porque la vista se centra en el espacio disponible.
Barra de navegación de UIN con botón izquierdo y derecho
Barra de navegación de UIN con un solo botón
Esta es mi implementación actual:
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;