-
Notifications
You must be signed in to change notification settings - Fork 0
How to use the palettes
To use the palettes, note that they are based on three main components:
- The palettes themselves, implemented in the ERPalettePanel class;
- The tab view, which act as anchors for the palettes and contain icons; and
- The holder view, which displaying the tab views over the main content.
You can use the palettes by employing only holder views but for more complex configurations, you will have to use the tab view class. To import the necessary files in your source code, just add #import <ERAppKit/ERPalette.h> at the beginning of your source files.
You can refer to the framework's demo app to see how to create and use palettes.
#Step 1: Creating the holder view
The simplest way to create and initialize a palette holder view for your interface is through XCode's interface builder.
If you already have a view displaying some content (for example, an image) and if you want to add bars around it, just embed it in a custom view (in the main menu: Editor -> Embed In -> Custom View) and change the view's class to ERPaletteHolderView. That's it, you're done!
If you only want to use the basic implementation of the holder view (displaying four bars, one for each side of the view), you can also choose the custom view's class to be ERBasicPaletteHolderView (we will describe the difference later).
Just do not forget to add an outlet from your delegate to your holder view.
#Step 2: Adding tab bars If you choose the basic holder view, you can skip this section
Once your holder view has been initialized, you will be able to add some tab bars. To do so, you can just use one of the following two methods:
- (ERPaletteTabView *)addTabViewWithPosition:(ERPalettePanelPosition)pos- (ERPaletteTabView *)addTabViewWithSize:(CGFloat)tabSize location:(CGFloat)location position:(ERPalettePanelPosition)pos
This will create a new tab view, add it to the holder view and return it. Use the first method if you want the tab to span the entire width (or height, depending on the position) of the holder view, or the second method if you want to specify the size and the location of the bar in the holder view.
You can use the returned value to set the autosizing masks of the tab bars (the default behavior might not be right for your application). You will also use this returned value when adding palettes to the tab bars.
#Step 3: Creating and adding palettes
When using the basic holder view, adding palettes couldn't be simpler! You simply need to call addPaletteWithContentView: icon: title: atPosition: to automatically create a palette with the specified content, icon and title and add it to the proper tab bar according to the position parameter.
For example, if you have set an outlet paletteContent to a view from your app delegate to a custom view, you can do:
[[self paletteHolder] addPaletteWithContentView:[self paletteContent]
icon:[NSImage imageNamed:@"MyIcon"]
title:@"Demo"
atPosition:ERPalettePanelPositionUp];Once you have created the tab bars referenced in the previous section, you just have to add them to the palettes. Use the ERPaletteTabView's method - addPaletteWithContentView:icon:title:.