Skip to content

Instantly share code, notes, and snippets.

@ShingoFukuyama
Created October 20, 2016 12:35
Show Gist options
  • Save ShingoFukuyama/d75251acbed6c4d93c41155dfa544c0f to your computer and use it in GitHub Desktop.
Save ShingoFukuyama/d75251acbed6c4d93c41155dfa544c0f to your computer and use it in GitHub Desktop.
Add border to UIButton on Xcode Interface Builder
//
// MyButton.h
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface MyButton : UIButton
@property (nonatomic, weak) IBInspectable UIColor *borderColor;
@property (nonatomic, assign) IBInspectable CGFloat borderWidth;
@end
// ------------------------------------------------------------------
// MyButton.m
#import "MyButton.h"
@implementation MyButton
- (instancetype)initWithFrame:(CGRect)frame
{
if (!(self = [super initWithFrame:frame])) return self;
self.borderColor = [UIColor blackColor];
self.borderWidth = 1;
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
self.layer.borderColor = self.borderColor.CGColor;
self.layer.borderWidth = self.borderWidth;
}
- (void)setBorderColor:(UIColor *)borderColor
{
_borderColor = borderColor;
self.layer.borderColor = self.borderColor.CGColor;
}
- (void)setBorderWidth:(CGFloat)borderWidth
{
_borderWidth = borderWidth;
self.layer.borderWidth = self.borderWidth;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment