I know this question has long, but recently i was in a similar situation so i decided to put my answer for those who are in a situation like this.
I wanted to be able to set the borderColor
and shadowColor
on an UIView
through the Interface Builder, but the type of a layer’s borderColor
property is CGColor
(just like shadowColor
) which is not one of the types allowed to be changed in the user-defined runtime attributes feature.
So i made an extension for CALayer
and i added two properties called borderColorIB and shadowColorIB that are of type UIColor:
RuntimeAttributes.h
@import QuartzCore;
@interface CALayer (IBConfiguration)
@property(nonatomic, assign) UIColor* borderColorIB;
@property(nonatomic, assign) UIColor* shadowColorIB;
@end
RuntimeAttributes.m
#import <UIKit/UIKit.h>
#import "RuntimeAttributes.h"
@implementation CALayer (IBConfiguration)
-(void)setBorderColorIB:(UIColor*)color
{
self.borderColor = color.CGColor;
}
-(UIColor*)borderColorIB
{
return [UIColor colorWithCGColor:self.borderColor];
}
-(void)setShadowColorIB:(UIColor*)color
{
self.shadowColor = color.CGColor;
}
-(UIColor*)shadowColorIB
{
return [UIColor colorWithCGColor:self.shadowColor];
}
@end
Now i alredy be able to set this two properties through Interface Builder like this:
- In the 'user-defined runtime attributes' section (Identity inspector)
Make sure the UIView is selected, and add the following runtime attributes:
- layer.borderWidth, Number, 1
- layer.borderColorIB, Color, someColor
<- my custom property to set the borderColor
- layer.shadowColorIB, Color, someColor
<- my custom property to set the shadowColor
- layer.shadowOpacity, Number, 0.8
- layer.shadowOffset, size, {5,5}
- layer.cornerRadius, Number, 5
Here is an image to show you how i did:

... and The result will be apparent during runtime, not in Xcode:

i hope this can help some people out there!