Created
January 4, 2019 23:19
-
-
Save aChase55/ac5cfa024ef226226f524e19b3cf27ca to your computer and use it in GitHub Desktop.
Rounded Corner View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface RoundedCornerView : UIView | |
@property (nonatomic) IBInspectable CGFloat cornerRadius; | |
@end | |
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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