custom UITableView header similar to UISearchBar

2019-02-15 22:53发布

I want to put my custom header view to UITableView with automatic scroll offset adjustments which UISearchBar have.

How I can do this?

1条回答
Fickle 薄情
2楼-- · 2019-02-15 23:57

Found workaround. I add my header to UISerachBar as subview and hide all other subviews of search bar

-(void)addHeaderView:(UIView *)view
{
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:view.frame];
    [searchBar layoutSubviews];

    UIView *searchBarView = searchBar.subviews[0];

    for (UIView *subview in searchBarView.subviews)
        subview.hidden = YES;

    view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [searchBarView addSubview:view];
    self.tableHeaderView = searchBar;
}
查看更多
登录 后发表回答