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

Overview

A simple translator from raw CSS rulesets to Objective-C values.

Objective-C values are created on-demand and cached. These ruleset objects are cached by NIStylesheet for a given CSS scope. When a memory warning is received, all ruleset objects are removed from every stylesheet.

Tasks

(void) - addEntriesFromDictionary:
 
(BOOL) - hasTextColor
 
(UIColor *) - textColor
 
(BOOL) - hasTextAlignment
 
(UITextAlignment) - textAlignment
 
(BOOL) - hasFont
 
(UIFont *) - font
 
(BOOL) - hasTextShadowColor
 
(UIColor *) - textShadowColor
 
(BOOL) - hasTextShadowOffset
 
(CGSize) - textShadowOffset
 
(BOOL) - hasLineBreakMode
 
(NSLineBreakMode) - lineBreakMode
 
(BOOL) - hasNumberOfLines
 
(NSInteger) - numberOfLines
 
(BOOL) - hasMinimumFontSize
 
(CGFloat) - minimumFontSize
 
(BOOL) - hasAdjustsFontSize
 
(BOOL) - adjustsFontSize
 
(BOOL) - hasBaselineAdjustment
 
(UIBaselineAdjustment) - baselineAdjustment
 
(BOOL) - hasOpacity
 
(CGFloat) - opacity
 
(BOOL) - hasBackgroundColor
 
(UIColor *) - backgroundColor
 
(BOOL) - hasBorderRadius
 
(CGFloat) - borderRadius
 
(BOOL) - hasBorderColor
 
(UIColor *) - borderColor
 
(BOOL) - hasBorderWidth
 
(CGFloat) - borderWidth
 
(BOOL) - hasWidth
 
(NICSSUnit- width
 
(NICSSUnit- top
 
(NICSSUnit- bottom
 
(NICSSUnit- left
 
(NICSSUnit- right
 
(BOOL) - hasTintColor
 
(UIColor *) - tintColor
 
(NSString *) - relativeToId
 
(NICSSUnit- horizontalPadding
 
(NICSSUnit- verticalPadding
 

Method Documentation

addEntriesFromDictionary:

Adds a raw CSS ruleset to this ruleset object.

- (void)addEntriesFromDictionary:(NSDictionary *)dictionary;

hasTextColor

Returns YES if the ruleset has a 'color' property.

- (BOOL)hasTextColor;

textColor

Returns the text color.

- (UIColor*)textColor;

hasTextAlignment

Returns YES if the ruleset has a 'text-align' property.

- (BOOL)hasTextAlignment;

textAlignment

Returns the text alignment.

- (UITextAlignment)textAlignment;

hasFont

Returns YES if the ruleset has a value for any of the following properties: font, font-family, font-size, font-style, font-weight.

- (BOOL)hasFont;
Discussion

Note: You can't specify bold or italic with a font-family due to the way fonts are constructed. You also can't specify a font that is both bold and italic. In order to do either of these things you must specify the font-family that corresponds to the bold or italic version of your font.

font

Returns the font.

- (UIFont*)font;

hasTextShadowColor

Returns YES if the ruleset has a 'text-shadow' property.

- (BOOL)hasTextShadowColor;

textShadowColor

Returns the text shadow color.

- (UIColor*)textShadowColor;

hasTextShadowOffset

Returns YES if the ruleset has a 'text-shadow' property.

- (BOOL)hasTextShadowOffset;

textShadowOffset

Returns the text shadow offset.

- (CGSize)textShadowOffset;

hasLineBreakMode

Returns YES if the ruleset has an '-ios-line-break-mode' property.

- (BOOL)hasLineBreakMode;

lineBreakMode

Returns the line break mode.

- (NSLineBreakMode)lineBreakMode;

hasNumberOfLines

Returns YES if the ruleset has an '-ios-number-of-lines' property.

- (BOOL)hasNumberOfLines;

numberOfLines

Returns the number of lines.

- (NSInteger)numberOfLines;

hasMinimumFontSize

Returns YES if the ruleset has an '-ios-minimum-font-size' property.

- (BOOL)hasMinimumFontSize;

minimumFontSize

Returns the minimum font size.

- (CGFloat)minimumFontSize;

hasAdjustsFontSize

Returns YES if the ruleset has an '-ios-adjusts-font-size' property.

- (BOOL)hasAdjustsFontSize;

adjustsFontSize

Returns the adjustsFontSize value.

- (BOOL)adjustsFontSize;

hasBaselineAdjustment

Returns YES if the ruleset has an '-ios-baseline-adjustment' property.

- (BOOL)hasBaselineAdjustment;

baselineAdjustment

Returns the baseline adjustment.

- (UIBaselineAdjustment)baselineAdjustment;

hasOpacity

Returns YES if the ruleset has an 'opacity' property.

- (BOOL)hasOpacity;

opacity

Returns the opacity.

- (CGFloat)opacity;

hasBackgroundColor

Returns YES if the ruleset has a 'background-color' property.

- (BOOL)hasBackgroundColor;

backgroundColor

Returns the background color.

- (UIColor*)backgroundColor;

hasBorderRadius

Returns YES if the ruleset has a 'border-radius' property.

- (BOOL)hasBorderRadius;

borderRadius

Returns the border radius.

- (CGFloat)borderRadius;

hasBorderColor

Returns YES if the ruleset has a 'border' or 'border-color' property.

- (BOOL)hasBorderColor;

borderColor

Returns the border color.

- (UIColor*)borderColor;

hasBorderWidth

Returns YES if the ruleset has a 'border' or 'border-width' property.

- (BOOL)hasBorderWidth;

borderWidth

Returns the border width.

- (CGFloat)borderWidth;

hasWidth

Returns YES if the ruleset has a 'width' property.

- (BOOL)hasWidth;

width

Returns the width.

- (NICSSUnit)width;

top

In combination with relativeToId, the margin fields control how a view is positioned relative to another.

- (NICSSUnit)top;
Discussion

margin-top: 0 means the top of this view will be aligned to the bottom of the view identified by relativeToId. A positive number will move this further down, and a negative number further up. A percentage will operate off the height of relativeToId and modify the position relative to margin-top:0. So -100% means "align top". A value of auto means we will align the center y of relativeToId with the center y of this view.

bottom

In combination with relativeToId, the margin fields control how a view is positioned relative to another.

- (NICSSUnit)bottom;
Discussion

margin-bottom: 0 means the bottom of this view will be aligned to the bottom of the view identified by relativeToId. A positive number will move this further down, and a negative number further up. A percentage will operate off the height of relativeToId and modify the position relative to margin-bottom:0. So -100% means line up the bottom of this view with the top of relativeToId. A value of auto means we will align the center y of relativeToId with the center y of this view.

left

In combination with relativeToId, the margin fields control how a view is positioned relative to another.

- (NICSSUnit)left;
Discussion

margin-left: 0 means the left of this view will be aligned to the right of the view identified by relativeToId. A positive number will move this further right, and a negative number further left. A percentage will operate off the width of relativeToId and modify the position relative to margin-left:0. So -100% means line up the left of this view with the left of relativeToId. A value of auto means we will align the center x of relativeToId with the center x of this view.

right

In combination with relativeToId, the margin fields control how a view is positioned relative to another.

- (NICSSUnit)right;
Discussion

margin-right: 0 means the right of this view will be aligned to the right of the view identified by relativeToId. A positive number will move this further right, and a negative number further left. A percentage will operate off the width of relativeToId and modify the position relative to margin-left:0. So -100% means line up the right of this view with the left of relativeToId. A value of auto means we will align the center x of relativeToId with the center x of this view.

hasTintColor

Returns YES if the ruleset has an '-ios-tint-color' property.

- (BOOL)hasTintColor;

tintColor

Returns the tint color.

- (UIColor*)tintColor;

relativeToId

When relativeToId is set, a view will be positioned using margin-* directives relative to the view identified by relativeToId.

- (NSString*)relativeToId;
Discussion

You can use id notation, e.g. #MyButton, or a few selectors: .next, .prev, .first and .last which find the obviously named siblings. Note that the mechanics or margin are not the same as CSS, which is of course a flow layout. So you cannot, for example, combine margin-top and margin-bottom as only margin-top will be executed.

Relative positioning also requires that you're careful about the order in which you register views in the engine (for now), since we will evaluate the rules immediately. TODO add some simple dependency management to make sure we've run the right views first.

horizontalPadding

For views that support sizeToFit, padding will add a value to the computed size.

- (NICSSUnit)horizontalPadding;

verticalPadding

For views that support sizeToFit, padding will add a value to the computed size.

- (NICSSUnit)verticalPadding;