Skip to content

Commit

Permalink
Fixed #131 which the search bar deformation on iOS 11
Browse files Browse the repository at this point in the history
Fixed #131 which the search bar deformation on iOS 11
  • Loading branch information
ko1o committed Nov 15, 2017
1 parent b5e0f1e commit feb193c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions PYSearch/PYSearchViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,18 @@ - (void)viewDidLayoutSubviews
}

UIButton *cancelButton = self.navigationItem.rightBarButtonItem.customView;
CGFloat buttonWidth = cancelButton.py_width;
CGFloat buttonHeight = cancelButton.py_height;
[cancelButton sizeToFit];
if (buttonWidth >= cancelButton.py_width) {
cancelButton.py_width = buttonWidth;
}
if (buttonHeight >= cancelButton.py_height) {
cancelButton.py_height = buttonHeight;
}
// Adapt the search bar layout problem in the navigation bar on iOS 11
// More details : https://github.com/iphone5solo/PYSearch/issues/108
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0) { // iOS 11
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.layoutMargins = UIEdgeInsetsZero;
CGFloat space = 8;
for (UIView *subview in navBar.subviews) {
if ([NSStringFromClass(subview.class) containsString:@"ContentView"]) {
subview.layoutMargins = UIEdgeInsetsMake(0, space, 0, space); // Fix cancel button width is modified
break;
}
}
_searchBar.py_width = self.view.py_width - cancelButton.py_width - PYSEARCH_MARGIN * 3 - 8;
_searchBar.py_height = self.view.py_width > self.view.py_height ? 24 : 30;
_searchTextField.frame = _searchBar.bounds;
Expand Down

0 comments on commit feb193c

Please sign in to comment.