小编Ste*_*ler的帖子

UINavigationBar TitleView带副标题

我想在我的UINavigationBar中有一个titleView,它有两行文本而不是一行

当我有一个"Back"-Button和一个"Edit"按钮时,我当前的实现效果很好,因为它看起来几乎居中.问题是我只有一个按钮.它看起来非常奇怪和错误,因为视图集中在可用空间上.

带左右按钮的UINavigationBar

UINavigationBar只有一个Button

这是我目前的实施:

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;
Run Code Online (Sandbox Code Playgroud)

uinavigationbar titleview ios

14
推荐指数
4
解决办法
2万
查看次数

标签 统计

ios ×1

titleview ×1

uinavigationbar ×1