如何在不使用文本框的情况下制作自定义搜索栏?

问题描述:

我试图使用故事板或代码使自定义搜索栏。有人可以使用Xcode的默认设置来提示有关自定义搜索栏的示例或代码。如何在不使用文本框的情况下制作自定义搜索栏?

我想复制IMDB应用程序的搜索栏。

https://itunes.apple.com/us/app/imdb-movies-tv-trailers-and-showtimes/id342792525?mt=8

+1

没有TextField?你如何写你想要搜索的东西? – Larme

+0

我只是在做设计。不是功能。我已经给你了我想要复制的链接。是的没有textfield –

+0

这就是UISearchbar –

_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 
self.view.bounds.size.width, 
self.navigationController.navigationBar.bounds.size.height)]; 
_searchBar.tintColor = [UIColor blueColor]; 

forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal]; 
_searchBar.placeholder = @"Enter drug name"; 
_searchBar.barTintColor = [UIColor clearColor]; 

UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"]; 
txfSearchField.backgroundColor = [UIColor whiteColor]; 
txfSearchField.tintColor = [UIColor blackColor]; 
txfSearchField.textColor = [UIColor blackColor]; 
_searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
_searchBar.delegate = self; 
_searchBar.showsCancelButton = NO; 
[_searchBar becomeFirstResponder]; 

[self.navigationController.navigationBar addSubview:_searchBar];

+0

谢谢@Vinay库马尔 –

+0

欢迎@ HarjotSingh –

+0

停止建议私人API,因为苹果会拒绝该应用程序,它会让人困惑! –