我已将 ImageView
设置为特定 ViewController 的标题 View ,而其他 Controller 将 UILabel
设置为标题 View 。我使用以下代码设置标题 View ,
UIImageView *imageTitle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo"]];
[self.navigationController.navigationBar.topItem setTitleView:imageTitle];
这个我也试过,
UIImageView *imageTitle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo"]];
[self.navigationItem setTitleView:imageTitle];
问题是,当我将标题 View 弹出回 View Controller 时 在左边停留几秒钟。我不确定这是什么原因?请让我知道哪里出错了???!
P.S: 此问题仅在 iOS 7 中出现!
这里是这个问题的示例项目 - https://dl.dropboxusercontent.com/u/97646145/Issue/NavigationTitleView.zip
更新
正如@FahimParkar 所建议的,我为标题 View 使用了 320x44 图像。由于图像很宽,定位延迟似乎很小。 这是这个问题的唯一解决方案吗?
下载带有 320x44 图像的试用项目的链接 -> https://dl.dropboxusercontent.com/u/97646145/Issue/NavigationTitleView_Updated.zip
最佳答案
正确设置导航有两种选择。
首先:
像下面那样设置 Titleview:-
- (void)viewDidLoad
{
UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
imgviw.backgroundColor = [UIColor blackColor];
imgviw.center=navView.center; // this is display your image at center of navigation bar.
imgviw.image=[UIImage imageNamed:@"passowrd.png"];
[navView addSubview:imgviw];
self.navigationItem.titleView = navView;
[super viewDidLoad];
}
输出如下:-
第二:
将导航图像设置为您对特定 view-controller
的要求。使用相同大小的导航栏创建导航图像。并使用波纹管代码进行设置。
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Navbar.png"] forBarMetrics:UIBarMetricsDefault];
关于ios - UINavigationBar 标题 View 对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23006033/