我创建了一个iPad应用程序,我希望将searchBar放在导航栏的右侧.
当我在导航栏中添加搜索栏时,它位于navigationBar的中间位置.在中间,相反,我想显示一个特定的图像.
我怎样才能做到这一点?
这是我的代码片段,
[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(位于中间).
解决方法
试试这个:
UISearchBar *searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0,100,40)] autorelease]; searchBar.backgroundImage = [[[UIImage alloc] init] autorelease]; self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:searchBar] autorelease];
您可以随时更改框架.请记住,backgroundImage属性仅在iOS 5中可用.您应该搜索替代选项以摆脱iOS 4.x的背景
如果这对您有用,请告诉我.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。