iOS: UIActivityIndicator in UISearchBar

Is it possible to display an UIActivityIndicator in the UISearchBar while searching?


  • Yes you can.

    When start searching create an activity indicator and add it as the subview of UISearchBar using addSubView method. When you finish the search remove it from the search bar using removeFromSuperView method.

    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    //set frame for activity indicator
    [searchBar addSubview: spinner];
    [spinner startAnimating];

    Refer this link for an alternative way.