使用IB_DESIGNABLE與IBInspectable實現可在SB編輯border與corner的Button

很是簡單,沒什麼好說的,直接上代碼吧;html

#import <UIKit/UIKit.h>

IB_DESIGNABLE
@interface RBButton : UIButton
@property (assign, nonatomic) IBInspectable CGFloat borderWidth;
@property (strong, nonatomic) IBInspectable UIColor *borderColor;
@property (assign, nonatomic) IBInspectable CGFloat cornerRadius;
@end

#import "RBButton.h"

@implementation RBButton

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

- (void)setBorderWidth:(CGFloat)borderWidth {
    self.layer.masksToBounds = YES;
    self.layer.borderWidth = borderWidth;
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = cornerRadius;
}

@end

而後-> 圖片描述
快去試試效果吧。ios

參考文檔:https://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_...xcode

相關文章
相關標籤/搜索