Last active
June 15, 2017 13:41
-
-
Save yabenatti/6d11a6b348ccb9c610f156ba5303bb5b to your computer and use it in GitHub Desktop.
ReusableView
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> | |
IB_DESIGNABLE //Reusable Views loaded from a xib file, you can see them on storyboard | |
@interface ReusableView : UIView | |
@property (weak, nonatomic) IBOutlet UILabel *message; | |
@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
#import "EmptyStateView.h" | |
@implementation EmptyStateView | |
#pragma mark - init methods | |
- (instancetype)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
if (self) { | |
// load view frame XIB | |
[self commonSetup]; | |
} | |
return self; | |
} | |
- (instancetype)initWithCoder:(NSCoder *)aDecoder { | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
// load view frame XIB | |
[self commonSetup]; | |
} | |
return self; | |
} | |
#pragma mark - setup view | |
- (UIView *)loadViewFromNib { | |
NSBundle *bundle = [NSBundle bundleForClass:[self class]]; | |
// An exception will be thrown if the xib file with this class name not found, | |
UIView *view = [[bundle loadNibNamed:NSStringFromClass([self class]) owner:self options:nil] firstObject]; | |
return view; | |
} | |
- (void)commonSetup { | |
UIView *nibView = [self loadViewFromNib]; | |
nibView.frame = self.bounds; | |
// the autoresizingMask will be converted to constraints, the frame will match the parent view frame | |
nibView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
// Adding nibView on the top of our view | |
[self addSubview:nibView]; | |
} | |
- (void)awakeFromNib { | |
[super awakeFromNib]; | |
} | |
@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
/* Set the file owner as the .h file above */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment