Customize¶
The Yahoo Search SDK allows developers to customize the look and feel of UI components, including the Search Bar, Tab Bar, and background.
Custom Header (Search Bar)¶
The Yahoo Search SDK provides a default Search Bar implementation. To customize the look and feel of the Search Bar, follow the steps below.
- Create a UIView subclass that follows the YSLHeaderProtocol:
// Objective-C @interface CustomHeaderView : UIView <YSLHeaderProtocol> ... @end// Swift class CustomHeaderView: UIView, YSLHeaderProtocol
- Set your Search View Controller’s headerView property to an instance of your CustomHeader class:
// Objective-C searchViewController.headerView = [CustomHeaderView new];// Swift var headerView: CustomHeaderView! = CustomHeaderView() searchViewController.headerView = headerViewYou can view more details regarding YSLHeaderProtocol and a working Custom HeaderView demo in the DemoApp.
Note
The custom header must have an option for users to dismiss the search view controller, such as a back button.
Custom Background¶
By default, Search View Controller uses a default color background for each individual tab. To use a custom background, you can insert your own UIViewController into the view hierarchy so that it is directly below the header and the footer:
- Create a new UIViewController that will serve as the background:
//Objective-C @interface BackgroundViewController : UIViewController// Swift class BackgroundViewController: UIViewController
- Set your Search View Controller’s
landingViewController
property to an instance of yourBackgroundViewController
class, and disable hiding of the landing page (by default, the landing page is hidden):// Objective-C searchViewController.landingPageViewController = [BackgroundViewController new]; searchViewController.hideLandingPage = NO;// Swift var backgroundViewController: BackgroundViewController! = BackgroundViewController() searchViewController.landingPageViewController = backgroundViewController searchViewController.hideLandingPage = false
Note
Setting the hideLandingPage
property before setting the landingPageViewController
won’t have any effect.
Custom Tabs¶
By default, Search View Controller presents Web, Image and Video search results for the queryString. But, it allows adding custom search results to the presentation as a separate tab.
Register a custom vertical class that complies to the
YSLSearchProtocol
with the search result type. This registration is saved in YSLSetting. So you don’t need to re-register for multiple YSLSearchViewController instances. Registering more than once or registering for the pre-defined search result type Web, Image, Video will throw a NSInvalidArgumentException exception.@interface MyCustomTab : UIViewController <YSLSearchProtocol> @end[[YSLSetting sharedSetting] registerSearchResultClass:[MyCustomTab class] forType:@"myTabResultType"];Registration alone does not present the custom search tab. You need to include that searchResultType in
setSearchResultTypes
API. You can decide the order in which the searchResultTypes have to be shown before the searchViewController is presented.YSLSearchViewController *searchViewController = [YSLSearchViewController new]; [searchViewController setSearchResultTypes:@[@"myTabResultType",YSLSearchResultTypeWeb,YSLSearchResultTypeImage,YSLSearchResultTypeVideo]];You can optionally choose to deregister the custom tab class. But, de-registration does not remove the custom tab from the presentation. After de-registration, setSearchResultTypes has to be called without the custom search result type to remove it from the presentation.
[[YSLSetting sharedSetting] deregisterSearchResultType:@"myTabResultType"];