0

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:

enter image description here

After Clicking in search bar:

enter image description here

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.

u_gandhi
  • 435
  • 1
  • 5
  • 23

2 Answers2

3

This happened to me as well, Just set this to NO.

self.definesPresentationContext = NO

check this: UISearchController Search Bar Position Drops 64 points

0

for swift 4.x, this worked for me

self.edgesForExtendedLayout = .bottom
Usman Shahid
  • 173
  • 1
  • 10