Light gray background in “bounce area” of a UITableView

前端 未结 16 2067
一整个雨季
一整个雨季 2020-11-28 23:05

Apple\'s iPhone apps such as Music and Contants use a search bar in a UITableView. When you scroll down so that the search bar moves down, the empty space above the scroll v

16条回答
  •  既然无缘
    2020-11-28 23:23

    Setting transparencies is bad for performance. What you want is the gray area above the search bar, but it should still be white beyond the end of the list.

    You can add a subview to your UITableView that lives above the content instead.

    CGRect frame = self.list.bounds;
    frame.origin.y = -frame.size.height;
    UIView* grayView = [[UIView alloc] initWithFrame:frame];
    grayView.backgroundColor = [UIColor grayColor];
    [self.listView addSubview:grayView];
    [grayView release];
    

    You could add more fancy stuff to the view if you like, perhaps a fade, or a divider line without subclassing UISearchBar.

提交回复
热议问题