我正在尝试推送视图控制器并设置其导航栏的标题,但由于我猜测使用了长标题,因此它没有居中。除此之外,后退按钮的范围增加到标题视图,即如果我点击Milestone的“M”,它会回来虽然它的帧是相同的。
后退按钮的界限是相同的,但其点击影响会延长。
下面是我如何推动视图控制器的代码。
MilestoneDetailsViewController *controller = [[MilestoneDetailsViewController alloc] initWithNibName:@"MilestoneDetailsViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
并在MilestoneDetailsViewController中,我将标题设置如下:
self.title = NSLocalizedString(@"Milestone Details", nil);
答案 0 :(得分:2)
后退按钮根据之前viewController的标题选择其大小。你可以将它改为一个空字符串,例如,在你之前的viewController中,你要从那里写下这段代码。
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@""
style:UIBarButtonItemStylePlain
target:nil
action:nil];
答案 1 :(得分:0)
试试这个
UILabel* lbNavTitle = [[UILabel alloc] initWithFrame:CGRectMake(0,40,320,40)];
lbNavTitle.textAlignment = UITextAlignmentCenter;
lbNavTitle.text = NSLocalizedString(@"Milestone Details!",@"");
self.title = lbNavTitle // here self.title is your navigation bar title
答案 2 :(得分:0)
试试这个
UIView *tView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 160 ,44)];
UILabel *bartitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 4, tView.frame.size.width, 40)];
[bartitleLabel setBackgroundColor:[UIColor clearColor]];
[bartitleLabel setTextAlignment:NSTextAlignmentCenter];
[bartitleLabel setAdjustsFontSizeToFitWidth:YES];
[bartitleLabel setText:NSLocalizedString(@"Milestone Details!",@"")];
[self.navigationItem setTitle:@""];
[tView addSubview:bartitleLabel];
[tView setBackgroundColor:[UIColor clearColor]];
[self.navigationItem setTitleView:tView];