-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKVICustomView.m
64 lines (42 loc) · 1.37 KB
/
KVICustomView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// KVICustomView.m
// Booya Fitness
//
// Created by Vasyl Khmil on 9/3/15.
// Copyright (c) 2015 MEV. All rights reserved.
//
#import "KVICustomView.h"
@interface KVICustomView ()
@property (nonatomic, readonly) NSString *nibName;
@end
@implementation KVICustomView
#pragma mark - Intializers
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self != nil) {
[self loadViewFromNib];
}
return self;
}
- (instancetype)init {
self = [super init];
if (self != nil) {
[self loadViewFromNib];
}
return self;
}
#pragma mark - Properties
- (NSString *)nibName {
return nibFileName == nil ? NSStringFromClass([self class]) : nibFileName;
}
#pragma mark - Private
- (void)loadViewFromNib {
UIView *view = (UIView *)[[NSBundle mainBundle] loadNibNamed:self.nibName owner:self options:nil].firstObject;
[self addSubview:view];
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary *bindings = @{@"view" : view};
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:bindings]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:bindings]];
view.backgroundColor = [UIColor clearColor];
}
@end