【发布时间】:2012-01-18 08:57:32
【问题描述】:
我创建了一个 iPad 应用程序,我希望我的 searchBar 位于导航栏的右侧。
当我在导航栏中添加搜索栏时,它位于导航栏的中间。相反,我想在中间显示一个特定的图像。
我怎样才能做到这一点?
这是我的代码 sn-p,
[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];
使用上面的代码,我只能在模拟器中看到 searchBar(位于中间)。
【问题讨论】:
-
首先,为什么要发布
titleView?也许你需要释放imageView。其次,如果将sBar添加到self.navigationItem.titleView,则只有条形可见。如果你想看到你需要这样做的图像:self.navigationItem.titleView = imageView. -
搜索栏可以试试看UIBarButtonItem reference。也许可以传入一个 UIView(如 UISearchBar)并将该按钮作为
self.navigationItem.rightBarButtonItem放在导航栏中
标签: iphone ios ipad uinavigationbar uisearchbar