【发布时间】:2016-10-31 16:40:17
【问题描述】:
下面是代码:
#import "LoginView.h"
@implementation LoginView
-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}
-(void) setup{
[[NSBundle mainBundle] loadNibNamed:@"LoginView" owner:self options:nil];
self.bounds = self.loginView.bounds;
[self addSubview:self.loginView];
}
现在我创建了一个视图控制器并向它添加了一个 UIView。在 viewWillAppear 中,我试图将 xib 文件加载到我的视图控制器中定义的 UIView 中。
-(void)viewWillAppear:(BOOL)animated{
self.containerView.layer.borderColor = [UIColor blackColor].CGColor;
self.containerView.layer.borderWidth = 2.0f;
LoginView *loginView = [[LoginView alloc] initWithFrame:CGRectMake(self.containerView.frame.origin.x,self.containerView.frame.origin.y, self.containerView.frame.size.width, self.containerView.frame.size.height)];
[self.containerView addSubview:loginView];
}
但是,xib 文件超出了我命名为 containerView 的已定义 UIView。我已将 containerView 链接到 ViewController 中的 UIView。
@property(nonatomic, weak) IBOutlet UIView *containerView;
谁能帮助我为什么会得到这个输出?我需要在 ViewController 的 containerView 中获取自定义 uiview。就像文本字段和按钮应该在黑色边框内一样。
【问题讨论】:
标签: ios objective-c uiview uiviewcontroller storyboard