2017-04-05 40 views
0

我有UIViewcontroler其具有兩個組件的大小寬度之一UITableView佔用:120和高度:603UIViewcontroller和另一個UIView(的DetailView)相關的屏幕。 (尺寸寬度:255 &身高:603如何自動調節的UIView幀到另一幀的UIView

現在我定製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];  
    } 

的CustomView不是自動上的DetailView UIView的屏幕調整。 的理解來解決框架

@Thanks提前

+0

什麼是detailView.frame中的loadView方法?你在哪裏調用這個方法? –

+0

@TejaNandamuri CustomView.frame = detailView.bounds;它有助於解決這個問題。我一會兒就啞了。 :d – kiran

回答

0

的問題是您在的DetailView的框架設置爲您customView並添加customView到您的DetailView你的建議將是有益的。

設置自定義視圖的框架,請使用以下代碼:

customView.frame = (CGRect){ 
    .origin = CGPointZero, 
    .size = detailView.frame.size 
    }; 

希望充分,這將解決您的問題。

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]; 

}