简体   繁体   中英

How to auto adjust UIView frame into another UIView Frame

I have UIViewcontroler which occupied with two component one UITableView of the size Width: 120 and Height:603 of UIViewcontroller and another one UIView (detailView) related screen. (size Width: 255 & Height: 603 )

Now I created on custom UIView (customView) now I want to added it on detailView, which is not fit to UIView

detailView Frame is half of uiviewcontroller view size. the custom view frame is normal ie width 375 & height 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];       
    }

The CustomView is not auto adjusted on the detailView UIView Screen. Your advice will be useful for understand to fix frame

@Thanks in advance

The problem is you are setting the detailView's frame to your customView and adding the customView into your detailView.

to set the frame of your custom view please use below code:

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

Hope fully this will solve your problem.

Your loadView Method is written like below

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM