Skip to content

Instantly share code, notes, and snippets.

@mmackh
Last active October 29, 2019 14:39
Show Gist options
  • Save mmackh/8821dd8a952df3cd84919f0cd9e42273 to your computer and use it in GitHub Desktop.
Save mmackh/8821dd8a952df3cd84919f0cd9e42273 to your computer and use it in GitHub Desktop.
Catalyst - NSToolbar Search
static NSString * toolbarIdentifierSearch = @"Search";
@interface IPDFToolbarItem : NSToolbarItem
@property (atomic,readwrite) id view;
@property CGSize minSize;
@property CGSize maxSize;
@end
@implementation IPDFToolbarItem
@dynamic view;
@dynamic minSize;
@dynamic maxSize;
@end
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSToolbarItemIdentifier)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
if (itemIdentifier == toolbarIdentifierSearch)
{
id searchField = [NSClassFromString(@"NSSearchField") new];
// fail here if something doesn't work out or customise further
IPDFToolbarItem *searchItem = [IPDFToolbarItem itemWithItemIdentifier:toolbarIdentifierSearch barButtonItem:nil];
searchItem.view = searchField;
searchItem.maxSize = CGSizeMake(240, 44);
return searchItem;
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment