简体   繁体   中英

View ignoring its own frame and getting height from subview

I'm adding a image to a image view and then adding the image view to a view. The custom view is ignoring its own frame and getting the height from the image view. How can I solve this?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIImage* image = [UIImage imageNamed:@"UILabelMe.png"];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, image.size.width, image.size.height)];
    [imageView setImage:image];

    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    [customView addSubview:imageView];

    return customView;

}

You need to also implement:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 

As per the docs , the header view will only work correctly when this is implemented.

The above code is working fine. try to add background color for CUSTOM VIEW and check it.

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