motion-kit/motion-kit — pull request #67 by jamonholmgren (2014-08-06 06:30:30+00:00)
Title: Added initial concept for MK::Appearance

*Not for merging*

@colinta , here's an initial concept I have for the `MK::Appearance` class. Essentially, the API works like this.

### Building the appearance

Simply instantiate your appearance object and then call a method (any method will do, but `build` is recommended for consistency) that applies your styles.

```ruby
class AppDelegate
def application(app, didFinishLaunchingWithOptions:options)
MyAppearance.new.build
end
end
```

### Defining your styles

Here's how it works:

```ruby
class MyAppearance < MK::Appearance
def build
style UIView do
background_color UIColor.orangeColor
end

style UIToolbar do
bar_tint_color UIColor.blueColor
background_image UIImage.imageNamed('Default-568h'), toolbar_position:UIToolbarPositionAny, bar_metrics:UIBarMetricsDefault
shadow_image UIImage.imageNamed('Default-568h'), toolbar_position:UIToolbarPositionAny
end

style UITableViewCell do
separator_inset UIEdgeInsetsMake(1.0, 2.0, 3.0, 4.0)
end

style UITableView do
separator_inset UIEdgeInsetsMake(1.0, 2.0, 3.0, 4.0)
section_index_color UIColor.purpleColor
section_index_background_color UIColor.greenColor
section_index_tracking_background_color UIColor.clearColor
end
end
end
```

### Testing

The above is tested and works. I have not yet tested nested styles, although it's preliminarily built (and hopefully working). That will be next, **if** you're happy with the direction I'm going.

### Implementation

I'm essentially using a completely separated approach to this. I'm not using BaseLayout or any other MotionKit components. With that in mind, this could easily become a separate gem.

I use "helpers" (which are modules, mixed in to the Appearance class) to apply styles. You can also apply styles yourself by using `appearance.setTintColor UIColor.blackColor` (much like `target.x` in regular MK layouts). There is no method_missing and I don't (currently) intend to put one, as the UIAppearance API is fairly limited in scope and we can provide helpers for all of them.

Thoughts?