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


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 {


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:
(NSString *) - descriptionForView:withName:
(NSString *) - descriptionForAllViews

Method Documentation


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;

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.


Initializes a newly allocated DOM with the given stylesheet.

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


Returns an autoreleased DOM initialized with the given stylesheet.

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


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

+ (id)domWithStylesheetWithPathPrefix:paths:;


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

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

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.


Registers the given view with the DOM.

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

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


Registers the given view with the DOM.

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

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.


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

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


Removes the association of a view with a CSS class.

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

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


Removes the given view from from the DOM.

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

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


Removes all views from from the DOM.

- (void)unregisterAllViews;


Reapplies the stylesheet to all views.

- (void)refresh;

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


Reapplies the stylesheet to a single view.

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

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


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

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

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.


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

- (NSString*)descriptionForAllViews;