美文网首页
使用IBInspectable在面板上添加属性

使用IBInspectable在面板上添加属性

作者: 爵笙彦 | 来源:发表于2016-06-01 17:48 被阅读7次

复制.h文件

//
//  UIView+GS.h
//  refresh
//
//  Created by apple on 16/6/1.
//  Copyright © 2016年 apple. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIView (GS)

@property (nonatomic, assign)IBInspectable CGFloat cornerRadius;
@property (nonatomic, assign)IBInspectable CGFloat borderWidth;
@property (nonatomic, strong)IBInspectable UIColor *borderColor;

@end

复制.m文件

//
//  UIView+GS.m
//  refresh
//
//  Created by apple on 16/6/1.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UIView+GS.h"
#import <objc/runtime.h>


@implementation UIView (GS)

- (UIColor *)borderColor
{
    return objc_getAssociatedObject(self, @selector(borderColor));
}

- (void)setBorderColor:(UIColor *)borderColor
{
    self.layer.borderColor = borderColor.CGColor;
}

- (CGFloat)cornerRadius
{
    return [objc_getAssociatedObject(self, @selector(cornerRadius)) floatValue];
}
- (void)setCornerRadius:(CGFloat)cornerRadius
{
    self.layer.cornerRadius = cornerRadius;
    self.layer.masksToBounds = YES;
}


- (CGFloat)borderWidth
{
    return [objc_getAssociatedObject(self, @selector(borderWidth)) floatValue];
}
- (void)setBorderWidth:(CGFloat)borderWidth
{
    self.layer.borderWidth = borderWidth;
    self.layer.masksToBounds = YES;
}

@end

相关文章

网友评论

      本文标题:使用IBInspectable在面板上添加属性

      本文链接:https://www.haomeiwen.com/subject/lnvhdttx.html