User Defined Runtime Attributes

设置View borderWidth/cornerRadius/borderColor




为了兼容CALayer 的KVC ,你得给CALayer增加一个分类
CALayer+BorderColor.h

#import <QuartzCore/QuartzCore.h>

#import <UIKit/UIKit.h>

 

@interface CALayer (BorderColor)

 

@property(nonatomic, strong) UIColor *borderColorFromUIColor; 

 

@end

 

#import "CALayer+BorderColor.h"

#import <objc/runtime.h>

 

@implementation CALayer (BorderColor)

 

- (UIColor *)borderColorFromUIColor {

    return objc_getAssociatedObject(self, @selector(borderColorFromUIColor));

}

 

-(void)setBorderColorFromUIColor:(UIColor *)color

{

    objc_setAssociatedObject(self, @selector(borderColorFromUIColor), color, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

    [self setBorderColorFromUI:self.borderColorFromUIColor];

}

 

- (void)setBorderColorFromUI:(UIColor *)color

{

    self.borderColor = color.CGColor;

}

 

 

@end

 

效果

 

posted @ 2015-04-14 16:55  菜鸟程序猿  阅读(538)  评论(0编辑  收藏  举报