我创建了一个iPad应用程序,我希望我的搜索栏位于导航栏的右侧。
当我将搜索栏添加到导航栏中时,它会被放置在导航栏的中间。而我想要在中间显示特定的图像。
如何实现这一点?
以下是我的代码片段:
使用上述代码后,我只能在模拟器中看到位于中间的搜索栏。
当我将搜索栏添加到导航栏中时,它会被放置在导航栏的中间。而我想要在中间显示特定的图像。
如何实现这一点?
以下是我的代码片段:
[self.navigationController.navigationBar setTintColor:[[UIColor alloc]initWithRed:150.0 / 255 green:22.0 / 255 blue:22.0 / 255 alpha:0.0]];
UIImage *image = [UIImage imageNamed:@"logo(1).png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationItem setTitleView:imageView];
self.navigationItem.titleView = sBar;
[titleView release];
使用上述代码后,我只能在模拟器中看到位于中间的搜索栏。
titleView
?也许你需要释放imageView
。其次,如果你将sBar
添加到self.navigationItem.titleView
中,只有该栏是可见的。如果你想看到图像,你需要这样做:self.navigationItem.titleView = imageView
。 - Lorenzo Bself.navigationItem.rightBarButtonItem
。 - Lorenzo B