Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Can';t在导航栏中心设置标题视图,增加后退按钮的范围_Ios_Uinavigationbar_Titleview - Fatal编程技术网

Ios Can';t在导航栏中心设置标题视图,增加后退按钮的范围

Ios Can';t在导航栏中心设置标题视图,增加后退按钮的范围,ios,uinavigationbar,titleview,Ios,Uinavigationbar,Titleview,我试图推动一个视图控制器,并设置其导航栏的标题,但它并没有居中,因为我猜长标题正在使用。同时,后退按钮的范围增加到标题视图,也就是说,如果我用里程碑的“M”点击,它会返回,尽管它的框架是相同的 “后退”按钮的边界相同,但其单击影响被拉长 下面是我如何推动视图控制器的代码 MilestoneDetailsViewController *controller = [[MilestoneDetailsViewController alloc] initWithNibName:@"Mileston

我试图推动一个视图控制器,并设置其导航栏的标题,但它并没有居中,因为我猜长标题正在使用。同时,后退按钮的范围增加到标题视图,也就是说,如果我用里程碑的“M”点击,它会返回,尽管它的框架是相同的

“后退”按钮的边界相同,但其单击影响被拉长

下面是我如何推动视图控制器的代码

 MilestoneDetailsViewController *controller = [[MilestoneDetailsViewController alloc] initWithNibName:@"MilestoneDetailsViewController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];
在MilestoneDetailsViewController中,我将标题设置为:

self.title = NSLocalizedString(@"Milestone Details", nil);
像这样试试

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
像这样试试

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

“后退”按钮根据上一个viewController的标题选择其大小。您可以将其更改为空字符串,例如,在上一个viewController中,您正在从中推动编写此代码

self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@""
        style:UIBarButtonItemStylePlain
       target:nil
       action:nil];

“后退”按钮根据上一个viewController的标题选择其大小。您可以将其更改为空字符串,例如,在上一个viewController中,您正在从中推动编写此代码

self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@""
        style:UIBarButtonItemStylePlain
       target:nil
       action:nil];
试试这个

    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];
试试这个

    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];


您是否编写了隐藏后退按钮文本的代码?最好的选择是使用自定义视图而不是导航bar@Wolverine:我用代码编辑了我的问题。@ZeeshanAnjum你能显示以前vc的导航栏吗?你写了隐藏后退按钮文本的代码吗?最好的选择是使用自定义视图而不是导航bar@Wolverine:我用代码编辑了我的问题。@ZeeshanAnjum你能显示以前vc的导航栏吗?我已经试过了,但它仍然有相同的行为,“项目详细信息”是前一个控制器的标题。无论我放在哪里,它都具有相同的行为。您必须更改前一个viewController中的backButton文本,而不是当前显示的文本。我已经尝试过此操作,但它仍然具有相同的行为,“项目详细信息”是前一个控制器的标题。无论我放在哪里,它都有相同的行为。您必须更改前一个viewController中的backButton文本,而不是当前显示的文本。这与直接设置字符串有什么不同?您的代码只是拾取文本lblNavTitle,而不是对齐方式等@ZeeshanAnjum这里我只创建了一个标签,并将该标签对齐方式与导航栏标题对齐center@ZeeshanAnjum我相信问题不在于标题,它是带后扣的size@ZeeshanAnjumbackbutton有什么问题?这与直接设置字符串有什么不同?您的代码只是拾取文本lblNavTitle,而不是对齐方式等@ZeeshanAnjum这里我只创建了一个标签,并将该标签对齐方式与导航栏标题对齐center@ZeeshanAnjum我相信问题不在于标题,而在于背后的扣子size@ZeeshanAnjum你的后扣有什么问题?