Developer

Creating Custom UI Elements

To intercept UI element creation notifications, use MAFUIElementCreatorDelegate, which lets you create custom subviews or decorate the ones created by the framework.

MAFUIElementCreatorDelegate declares these APIs:

  • - (UIView*) willCreateUIElementWithId:(NSString*)uiElementId_in listItemIndex:(NSNumber*)listItemIndex_in tileDescriptor:(MAFTileDescriptorBase*)tileDescriptor_in context:(MAFContext*)context_in;

    Implement this delegate method and return a valid UIView* to create a custom UI element. The method is invoked by the framework before subviews are created; therefore, you can use the uiElementId_in parameter to intercept only the UI elements of your choice. The tileDescriptor_in parameter provides additional information about the subview’s tile.

  • - (void) didCreateUIElement:(UIView**)uiElement_in_out id:(NSString*)uiElementId_in listItemIndex:(NSNumber*)listItemIndex_in tileDescriptor:(MAFTileDescriptorBase*)tileDescriptor_in context:(MAFContext*)context_in;

    This delegate method is invoked after a UI Element is created. uiElement_in_out is passed as a reference, so you can decorate or replace the UIView.

  • - (UIViewController*) willCreateViewControllerWithUIElementId:(NSString*)uiElementId_in listItemIndex:(NSNumber*)listItemIndex_in tileDescriptor:(MAFTileDescriptorBase*)tileDescriptor_in context:(MAFContext*)context_in;

    Implement this delegate method to provide a custom view controller for specific views. Register the delegate via the MAFTileCreatorDelegate’s registerUIElementCreatorDelegateForTile: API.

Example

This example demonstrates how to create a UILabel with the ID “CustomLabel” in the configuration and return to the Extensibility Framework, which adds the label as a subview to the tile:
- (UIView*) willCreateUIElementWithId:(NSString*)uiElementId_in listItemIndex:(NSNumber*)listItemIndex_in tileDescriptor:(MAFTileDescriptorBase*)tileDescriptor_in context:(MAFContext*)context_in
{  
    UIView* result = nil;
    if ([uiElementId_in isEqualToString:@"CustomLabel "])
   {
        UILabel* label = [[[UILabel alloc] init] autorelease];
        label.text = @"This is a custom Label";
        label.textColor = [UIColor redColor];
        label.backgroundColor = [UIColor yellowColor];
        result = label;
    }
    return result;
}