Search code examples
iosobjective-cuikituiappearance

How can I access a class's appearance proxy in a class method which performs custom drawing?


I've set a 'tintColor' property on an appearance proxy for a UIView subclass class which can draw one of 5 different shapes using CAShapeLayer and UIBezierPath. I am using a class method to return a UIView the required shape:

+(CustomView*)viewForType:(CustomViewType)type
{
    CustomView* iV = [[CustomView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

    switch (type)
    {
        case CustomViewTypeOne:
    {
        iV.shapeLayer = [CAShapeLayer layerWithPath:[self typeOneBezierPath]
                                              color:[UIColor whiteColor]];
        break;
    }
    ...

    return iV;
}

How can I pass the 'tintColor' property I set on the appearance proxy to this method?

Edit: It may be worth mentioning not all of the returned views are the same, some of them contain one shape layer while others may contain multiple layers and make use of masking.


Solution

  • Do you need to pass the tint color property to this method? If you set the tint color to the appearance of theCustomView class, you can easily get the tint color back, using

    UIColor *tintColor = [[CustomView appearance] tintColor];