DACircularProgress
DACircularProgress copied to clipboard
Can not be showed successfully when make it as a component of my self-defined view when load from xib
I have a self-defined view. And it has a DACircularProgressView as subview.
@interface TestView : UIView
{
DACircularProgressView *_progressView;
}
@property(nonatomic, strong)DACircularProgressView *progressView;
And I want this TestView loaded from xib files. So my implementation file as below:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self _myInitialize];
}
return self;
}
- (void)awakeFromNib
{
[self _myInitialize];
}
- (void)_myInitialize
{
_progressView = [[DACircularProgressView alloc] initWithFrame:self.bounds];
_progressView.trackTintColor = [UIColor grayColor];
_progressView.progressTintColor = [UIColor greenColor];
[self addSubview:_progressView];
}
When add my TestView to my view controller's xib file, I can't see the right progress view. While when I alloc my TestView in viewDidLoad
method, and add it to my self.view
, I can see the right progress view. I want know why? Is there any mistake I have made? Thanks advance.
This is because the XIB calls initWithCoder and not initWithFrame. Just add this below initWithFrame
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
// Custom Setup
[self _myInitialize];
}
return self;
}