I have written code for searchBar in Objective C for iOS devices and it is working fine on iPhone but when it comes to iPad it is changing its x value and due to which cancel button is also hiding.
Initially Search bar looks like:
After Clicking in search bar:
Does anybody face this issue and suggest me something in this ?
Here is the code:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
followTableView.tableHeaderView = self.searchController.searchBar;
UISearchBar.appearance.tintColor = [UIColor whiteColor]; //Cancel button color
[self.searchController.searchBar sizeToFit];
tapGesture = [[UITapGestureRecognizer alloc]init];
[tapGesture addTarget:self action:@selector(tapGestureBtnAction:)];
self.searchController.searchBar.barTintColor = searchBarColor;
-(IBAction)tapGestureBtnAction:(id)sender
{
[_searchController.searchBar resignFirstResponder];
[self.view removeGestureRecognizer:tapGesture];
}
Thanks in advance.
This happened to me as well, Just set this to NO.
self.definesPresentationContext = NO
check this: UISearchController Search Bar Position Drops 64 points