Skip to content

Instantly share code, notes, and snippets.

@aChase55
Created January 4, 2019 23:19
Show Gist options
  • Save aChase55/ac5cfa024ef226226f524e19b3cf27ca to your computer and use it in GitHub Desktop.
Save aChase55/ac5cfa024ef226226f524e19b3cf27ca to your computer and use it in GitHub Desktop.
Rounded Corner View
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface RoundedCornerView : UIView
@property (nonatomic) IBInspectable CGFloat cornerRadius;
@end
NS_ASSUME_NONNULL_END
IB_DESIGNABLE
@interface RoundedCornerView()
@end
@implementation RoundedCornerView
-(instancetype)init {
if (self = [super init]) {
[self roundCorners];
}
return self;
}
-(instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self roundCorners];
}
return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
[self roundCorners];
}
return self;
}
-(void)awakeFromNib {
[super awakeFromNib];
[self roundCorners];
}
-(void)prepareForInterfaceBuilder {
[super prepareForInterfaceBuilder];
[self roundCorners];
}
-(void)roundCorners {
self.clipsToBounds = YES;
self.layer.cornerRadius = self.cornerRadius;
self.layer.maskedCorners = kCALayerMaxXMinYCorner | kCALayerMinXMinYCorner;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment