Last active
July 12, 2018 04:34
-
-
Save sasaujp/80b2813ee82127bddfa1 to your computer and use it in GitHub Desktop.
コードからもIBからも使えるUIViewのサブクラスのinitに関して ref: https://qiita.com/sasau/items/9dd4e1c78ee669603ddb
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
@interface HogeView: UIView | |
@property(nonatomic)UIView *fugaView; | |
@end | |
@implementation HogeView | |
- (instancetype)initWithFrame:(CGFrame)frame { | |
self = [super initWithFrame:frame]; | |
if(self) { | |
[self setup]; | |
} | |
return self; | |
} | |
- (instancetype)initWithCoder:(NSCoder *)aDecoder { | |
self = [super initWithCoder:aDecoder]; | |
if(self) { | |
[self setup]; | |
} | |
return self; | |
} | |
- (void)setup { | |
self.fugaView = [UIView new]; | |
[self addSubview:self.fugaView]; | |
} | |
@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
class HogeView: UIView { | |
let fugaView: UIView | |
init(_ coder: NSCoder? = nil) { | |
// common initialize | |
fugaView = UIView.init() | |
if let coder = coder { | |
super.init(coder: coder)! | |
} else { | |
super.init(frame: CGRect.zero) | |
} | |
// common setup | |
addSubview(fugaView) | |
} | |
required convenience init?(coder aDecoder: NSCoder) { | |
self.init(aDecoder) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment