Imagine we are building a control called MYCircularSlider which will behave like a UISlider but will render in a circular/dial shape. We want the control to be highly configurable as its used throughout the app in different border styles, colors, radius etc.

This is what MYCircularSlider.h looks like

typedef NS_ENUM(NSUInteger, MYBorderStyle) {
    MYBorderStyleNone,
    MYBorderStyleLine,
    MYBorderStyleBezel,
};

@interface MYCircularSlider : UIControl

@property (nonatomic, strong) UIColor *trackTintColor;
@property (nonatomic, strong) UIColor *fillColor;
@property (nonatomic, assign) CGFloat trackRadius;
@property (nonatomic, assign) UIEdgeInsets thumbInsets;
@property (nonatomic, assign) MYBorderStyle trackBorderStyle;

- (void)setThumbTintColor:(UIColor *)thumbTintColor forState:(UIControlState)state;

@end

When classy encounters MYCircularSlider for the first time it will use reflection to determine the types of MYCircularSlider's properties. So without doing any configuration you can style most of the properties

MYCircularSlider  { 
  track-tint-color blue
  fill-color #CCDE73
  track-radius 40
  thumb-insets 2, 4, 2, 4
}
        

Unfortunately the Objective-C runtime doesn't give us back enough information to configure enums and selectors automatically. In these cases you can manually tell Classy what todo.

Configuration code should be placed before setting the [CASStyler defaultStyler].filePath.
See the getting started section.

Enums

To configure the MYBorderStyle property trackBorderStyle

// Retrieve class descriptor
CASObjectClassDescriptor *sliderClassDescriptor = [CASStyler.defaultStyler objectClassDescriptorForClass:MYCircularSlider.class];

// Creating border mapping
NSDictionary *borderStyleMap = @{
    @"none"   : @(MYBorderStyleNone),
    @"line"   : @(MYBorderStyleLine),
    @"bezel"  : @(MYBorderStyleBezel)
};

// Set mapping for property key
[sliderClassDescriptor setArgumentDescriptors:@[[CASArgumentDescriptor argWithValuesByName:borderStyleMap]] forPropertyKey:@cas_propertykey(MYCircularSlider, trackBorderStyle)];

Selectors

To configure the selector setThumbTintColor:forState:

CASArgumentDescriptor *colorArg = [CASArgumentDescriptor argWithClass:UIColor.class];

NSDictionary *controlStateMap = @{
    @"normal"       : @(UIControlStateNormal),
    @"highlighted"  : @(UIControlStateHighlighted),
    @"disabled"     : @(UIControlStateDisabled),
    @"selected"     : @(UIControlStateSelected),
};
CASArgumentDescriptor *stateArg = [CASArgumentDescriptor argWithName:@"state" valuesByName:controlStateMap];

[sliderClassDescriptor setArgumentDescriptors:@[colorArg, stateArg] setter:@selector(setThumbTintColor:forState:) forPropertyKey:@"thumbTintColor"];

Now we can style MYCircularSlider completely

MYCircularSlider  { 
  track-tint-color blue
  fill-color #CCDE73
  track-radius 40
  thumb-insets 2, 4, 2, 4
  
  track-border-style bezel
  thumb-tint-color white
  thumb-tint-color[state:highlighted] green
  thumb-tint-color[state:disabled] #999
}