The iOS framework that grows only as fast as its documentation
NIDOM Class Reference

Overview

A leight-weight DOM-like object to which you attach views and stylesheets.

To be clear: this is not an HTML DOM, but its intent is the same. NIDOM is designed to simplify the view <=> stylesheet relationship. Add a view to the DOM and it will automatically apply any applicable styles from the attached stylesheet. If the stylesheet changes you can refresh the DOM and all registered views will be updated accordingly.

Because NimbusCSS supports positioning and sizing using percentages and relative units, the order of view registration is important. Generally, you should register superviews first, so that any size calculations on their children can occur after their own size has been determined. It's not feasible (or at least advisable) to try and untangle these dependencies automatically.

Example Use

NIDOM is most useful when you create a single NIDOM per view controller.

NIStylesheet* stylesheet = [stylesheetCache stylesheetWithPath:@"root/root.css"];
// Create a NIDOM object in your view controller.
_dom = [[NIDOM alloc] initWithStylesheet:stylesheet];

You then register views in the DOM during loadView or viewDidLoad.

// Registers a view by itself such that only "UILabel" rulesets will apply.
[_dom registerView:_label];
// Register a view with a specific CSS class. Any rulesets with the ".background" scope will
// apply to this view.
[_dom registerView:self.view withCSSClass:@"background"];

Once the view controller unloads its view you must unregister all of the views from your DOM.

- (void)viewDidUnload {
}

Tasks

Dynamic View Construction
id target property
 
Creating NIDOMs
(id) - initWithStylesheet:
 
(id) + domWithStylesheet:
 
(id) + domWithStylesheetWithPathPrefix:paths:
 
(id) + domWithStylesheet:andParentStyles:
 
Registering Views
(void) - registerView:
 
(void) - registerView:withCSSClass:
 
(void) - unregisterView:
 
(void) - unregisterAllViews
 
Re-Applying All Styles
(void) - addCssClass:toView:
 
(void) - removeCssClass:fromView:
 
(void) - refresh
 
(void) - refreshView:
 
Debugging
(NSString *) - descriptionForView:withName:
 
(NSString *) - descriptionForAllViews
 

Method Documentation

target

Using the [UIView buildSubviews:inDOM:] extension allows you to build view hierarchies from JSON (or anything able to convert to NSDictionary/NSArray of simple types) documents, mostly for prototyping.

@property (nonatomic) id target;
Discussion

Those documents can specify selectors, and those selectors need a target. This target property will be the target for all selectors in a given DOM. Truth is it only matters during buildSubviews, so in theory you could set and reset it across multiple build calls if you wanted to.

initWithStylesheet:

Initializes a newly allocated DOM with the given stylesheet.

- (id)initWithStylesheet:(NIStylesheet *)stylesheet;

domWithStylesheet:

Returns an autoreleased DOM initialized with the given stylesheet.

+ (id)domWithStylesheet:(NIStylesheet *)stylesheet;

domWithStylesheetWithPathPrefix:paths:

Returns an autoreleased DOM initialized with a nil-terminated list of file paths.

+ (id)domWithStylesheetWithPathPrefix:paths:;

domWithStylesheet:andParentStyles:

Returns an autoreleased DOM initialized with the given stylesheet and a "parent" stylesheet that runs first.

+ (id)domWithStylesheet:(NIStylesheet *)stylesheet andParentStyles:(NIStylesheet *)parentStyles;
Discussion

Doing this rather than compositing stylesheets can save memory and improve performance in the common case where you have a set of global styles and a bunch of view or view controller specific style sheets.

registerView:

Registers the given view with the DOM.

- (void)registerView:(UIView *)view;
Discussion

The view's class will be used as the CSS selector when applying styles from the stylesheet.

registerView:withCSSClass:

Registers the given view with the DOM.

- (void)registerView:(UIView *)view withCSSClass:(NSString *)cssClass;
Discussion

The view's class as well as the given CSS class string will be used as the CSS selectors when applying styles from the stylesheet.

addCssClass:toView:

Create an association of a view with a CSS class and apply relevant styles immediately.

- (void)addCssClass:(NSString *)cssClass toView:(UIView *)view;

removeCssClass:fromView:

Removes the association of a view with a CSS class.

- (void)removeCssClass:(NSString *)cssClass fromView:(UIView *)view;
Discussion

Note that this doesn't "undo" the styles that the CSS class generated, it just stops applying them in the future.

unregisterView:

Removes the given view from from the DOM.

- (void)unregisterView:(UIView *)view;
Discussion

Once a view has been removed from the DOM it will not be restyled when the DOM is refreshed.

unregisterAllViews

Removes all views from from the DOM.

- (void)unregisterAllViews;

refresh

Reapplies the stylesheet to all views.

- (void)refresh;
Discussion

Since there may be positioning involved, you may need to reapply if layout or sizes change.

refreshView:

Reapplies the stylesheet to a single view.

- (void)refreshView:(UIView *)view;
Discussion

Since there may be positioning involved, you may need to reapply if layout or sizes change.

descriptionForView:withName:

Describe what would be done to view given the existing registrations for it.

- (NSString*)descriptionForView:(UIView *)view withName:(NSString *)viewName;
Discussion

In other words, you must call one of the register view variants first before asking for a description. The current implementations return actual objective-c code, using viewName as the target. This allows you to theoretically replace the CSS infrastructure with generated code, if you choose to. More importantly, it allows you to debug what's happening with view styling.

descriptionForAllViews

Call descriptionForView for all registered views, in the order they would be applied during refresh.

- (NSString*)descriptionForAllViews;