编写自定义弹出视图的更好方法是使用xib

时间:2017-07-21 06:33:06

标签: objective-c

到目前为止,我在StePopView.m文件中所做的是:

+(instancetype)loadFromXib{
    return [[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil][0];
}
-(void)awakeFromNib{
    [super awakeFromNib];
    //configure my view
    self.backgroundColor = [[UIColor colorWithWebStr:@"050205"] colorWithAlphaComponent:0.33];

}
//when move to superView, call show method to show a pop view with animation 
-(void)didMoveToSuperview{
    [self show];
}
-(void)show{
    //show a pop view with animation
}

当我在superView中使用此弹出视图时:

StePopView* popView = [StePopView loadFromXib]; 
popView.frame.bounds = self.bouds;
[self addSubView:popView]

这是一个更好的编码吗?什么是更好的代码,为什么?提前致谢!

0 个答案:

没有答案
相关问题