developer

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 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:

  1. Create a new UIViewController that will serve as the background:
//Objective-C
@interface BackgroundViewController : UIViewController
// Swift
class BackgroundViewController: UIViewController
  1. Set your Search View Controller’s landingViewController property to an instance of your BackgroundViewController 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.

  1. 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"];
    
  2. 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]];
    
  3. 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"];