xib嵌套使用注意

http://www.tuicool.com/articles/ENv6Nf

// 被使用的xib需要重写此方法

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        
//        UIView *containerView = [[UINib nibWithNibName:@"SecondView" bundle:nil] instantiateWithOwner:self options:nil][0];
        
        UIView *containerView = [[NSBundle mainBundle] loadNibNamed:@"SecondView" owner:self options:nil][0];
        
        CGRect newFrame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
        
        containerView.frame = newFrame;
        
        [self addSubview:containerView];
        
    }
    return self;
}

原文地址:https://www.cnblogs.com/jzlblog/p/4369369.html