How to override "searchBar" property in subclass of UISearchController?
<p>I have the problem like this: <a href="https://stackoverflow.com/questions/8496310/hide-uisearchbar-cancel-button">Hide UISearchBar Cancel Button</a></p>

<p>I have subclassed <code>UISearchController</code> and <code>UISearchBar</code>, and override methods <code>layoutSubviews</code> in <code>UISearchBar</code>.</p>

<p>How to override <code>searchBar</code> property with custom <code>UISearchBar</code> in my custom <code>UISearchController</code>?</p>

<p>Update 1</p>

<p>To implement property with custom <code>UISearchBar</code> i do in <code>MyUISearchController</code>:</p>

<pre><code>@property(nonatomic, strong, readonly) UISearchBar *searchBar;
</code></pre>

<p>And</p>

<pre><code>@synthesize searchBar=_searchBar;

- (UISearchBar *)searchBar {
    return [MySearchBar new];
}
</code></pre>

<p>But <code>UISearchController</code> uses default <code>searchBar</code> anyway..</p>

<p><strong>Update</strong></p>

<p>In <code>h</code> file:</p>

<pre><code>@interface MySearchController : UISearchController &lt;UITableViewDelegate, UITableViewDataSource&gt;
</code></pre>

<p>In <code>m</code> file:</p>

<pre><code>@interface MySearchController () &lt;UISearchDisplayDelegate, UISearchControllerDelegate,
UISearchBarDelegate, UISearchResultsUpdating, SearchAutocompleteLoader&gt;

@property UISearchController *searchController;

@property (strong, nonatomic) UITableView *searchResultTable;
@property UIView *viewForSearchBar;
@property (nonatomic) NSInteger filterSettings;
@property (strong, nonatomic) UILabel *matchesLabel;
@property (strong, nonatomic) UIView *loading;
@property (strong, nonatomic) UIView *foggView;

@end

- (instancetype)initWith:(UIView *)viewForSearch foggView:(UIView *)view delegate:(id)delegate andResultTableView:(UITableView *)tableView
{
    self.viewForSearchBar = viewForSearch;
    self.searchResultTable = tableView;
    self.foggView = view;
    self.searchDelegate = delegate;
    [self configureSearchController];
    return self;
}

- (void)configureSearchController {
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

    self.searchController.searchResultsUpdater = self;
    self.searchController.delegate = self;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    [self loadFilterSettings];
    self.searchController.searchBar.delegate = self;
    [self.searchController.searchBar setShowsCancelButton:NO];
    //self.searchController.searchBar.searchBarStyle = UISearchBarStyleDefault;

    [self.searchController.searchBar setBackgroundImage:[UIImage imageWithCGImage:(__bridge CGImageRef)([UIColor clearColor])]];
    [self.searchController.searchBar setImage:[UIImage imageNamed:@"iconSearchSettings"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];
    self.searchController.searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, self.viewForSearchBar.frame.size.height);
    self.viewForSearchBar.tintColor = [UIColor yellowColor];
   // [self.viewForSearchBar addSubview:self.searchController.searchBar];

    self.searchController.searchBar.barTintColor = [UIColor whiteColor];
    self.searchController.searchBar.tintColor = [UIColor blackColor];
    //self.searchController.searchBar.backgroundColor = [UIColor whiteColor];

    [self.viewForSearchBar addSubview:self.searchController.searchBar];

    for (UIView *subView in self.searchController.searchBar.subviews) {
        if ([subView isKindOfClass:[UITextField class]]) {
            [subView setTintColor:[UIColor blueColor]];
            [[(UITextField *) subView valueForKey:@"textInputTraits"] setValue:[UIColor blueColor] forKey:@"insertionPointColor"];
        }
    }

    [self.searchController setActive:YES];
    [self.searchController setActive:NO];
}
</code></pre>