Change Uibarbuttonitem from Uisearchbar

iOS 11 UINavigationBar UISearchBar and UIBarButtonItem overlap

Try DispatchQueue.main.async

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
DispatchQueue.main.async {
if self.traitCollection.horizontalSizeClass == .regular {
self.navigationItem.leftBarButtonItem = self.button
} else {
self.navigationItem.leftBarButtonItem = nil
}
}
}

iOS 8 search bar in a UIBarButtonItem?

Add a Search Bar and Display Controller next to your UITableViewController First Responder in your UI.

Add the UISearchBarDelegate and UISearchDisplayDelegate in your code and in your viewDidLoad method add the following code to display the search bar in the navigation bar:

Objective-C:

self.searchDisplayController.displaysSearchBarInNavigationBar = YES;

Swift:

self.searchDisplayController?.displaysSearchBarInNavigationBar = true

Then execute the delegate methods:

Objective-C:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

Swift:

func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool
func searchBar(searchBar: UISearchBar, textDidChange searchText: String)

Changing the font style for UISearchBar cancel button

Try something like this it worked for me.

 UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).setTitleTextAttributes([NSFontAttributeName : UIFont(name: "OpenSans", size: 15)!], forState: .Normal)

If you want to change the color as well add this to your array of attributes.

 NSForegroundColorAttributeName : UIColor.whiteColor()

Note: Made available in iOS 9

How to change the default text of Cancel Button which appears in the UISearchBar +iPhone

You also need to have the "searchBar setShowsCancelButton" before the procedure.

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[theSearchBar setShowsCancelButton:YES animated:NO];
for (UIView *subView in theSearchBar.subviews){
if([subView isKindOfClass:[UIButton class]]){
[(UIButton*)subView setTitle:@"Done" forState:UIControlStateNormal];
}
}
}

Note also: use UIButton to avoid problems with Apple!

Animate UISearchBar and UIBarButtonItem simultaneously with UISearchController

In case anyone is interested, I managed to make it work using UISearchDisplayController. See this sample project.

I'm still interested by a solution that works with UISearchController though.



Related Topics



Leave a reply



Submit