user3246173
user3246173

Reputation: 488

Prevent UISearchBar from indenting right when tapped

In my viewDidLoad, I programmatically create a search bar. When the search field is tapped, the search bar indents to the right. Why is this happening and how do I prevent it from doing so? I am not using autolayout.

- (void)createSearchBar {
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.searchBar.delegate = self;
    [self.searchController.searchBar sizeToFit];
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    self.definesPresentationContext = YES;
    self.edgesForExtendedLayout = UIRectEdgeNone;
}

enter image description here

Upvotes: 0

Views: 205

Answers (1)

Shubham Chawla
Shubham Chawla

Reputation: 132

you can try using the positionAdjustmentForSearchBarIcon: or setPositionAdjustment:forSearchBarIcon: message calls to the searchbar inside the delegate call:searchBarTextDidBeginEditing:

Upvotes: 0

Related Questions