How to resize a tableHeaderView of a UITableView?

后端 未结 19 2244
死守一世寂寞
死守一世寂寞 2020-11-29 16:14

I\'m having trouble resizing a tableHeaderView. It simple doesn\'t work.

1) Create a UITableView and UIView (100 x 320 px);

2) Set the UIView as tableHeaderV

19条回答
  •  猫巷女王i
    2020-11-29 17:07

    If your tableHeaderView is a content adjustable webView,you can try:

    [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
    
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        self.webView.height = self.webView.scrollView.contentSize.height;
        self.tableView.tableHeaderView = self.webView;
    }
    

    I tested it on iOS9 and iOS11,worked well.

提交回复
热议问题