我UIViewcontroler
占用了两个组件UITableView
,其大小为宽度:120和高度:603 的UIViewcontroller
和另一个UIView
(detailView)相关屏幕。 (尺寸宽度:255&高度:603 )
现在我在自定义UIView
(customView)上创建了我想在detailView上添加它,这不适合UIView
detailView Frame是uiviewcontroller视图大小的一半。 自定义视图框架是正常的,即宽度375&身高667
-(void)loadView {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil];
customView = [nibObjects objectAtIndex:0];
customView.frame = detailView.frame;
customView.layer.shadowColor = [UIColor blackColor].CGColor;
customView.layer.shadowRadius = 1.0f;
customView.layer.shadowOpacity = 1;
customView.layer.shadowOffset = CGSizeZero;
customView.layer.masksToBounds = YES;
[detailView addObject:customView];
}
在detailView UIView屏幕上不会自动调整CustomView。 您的建议对于理解修复框架
非常有用@Thanks提前
答案 0 :(得分:0)
问题是您要将detailView的框架设置为customView并将customView添加到detailView中。
要设置自定义视图的框架,请使用以下代码:
customView.frame = (CGRect){
.origin = CGPointZero,
.size = detailView.frame.size
};
希望完全能解决你的问题。
答案 1 :(得分:0)
您的loadView方法编写如下
-(void)loadView {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil];
customView = [nibObjects objectAtIndex:0];
customView.frame = CGRectMake(0, 0, detailView.frame.size.width, detailView.frame.size.height);
customView.layer.shadowColor = [UIColor blackColor].CGColor;
customView.layer.shadowRadius = 1.0f;
customView.layer.shadowOpacity = 1;
customView.layer.shadowOffset = CGSizeZero;
customView.layer.masksToBounds = YES;
[detailView addSubview:customView];
}