是否可以使 UIRefreshControl 的背景随着控件的增长而增长?
我希望刷新控件的背景颜色与顶部单元格的背景颜色相匹配。更改 tableview 的背景颜色是 Not Acceptable ,因为底部的空单元格也会有颜色,但我需要它们保持白色。
Apple 的邮件应用程序显示了此行为。刷新控件的背景与灰色搜索栏相匹配,但表格 View 底部的空单元格仍然是正常的白色。
下面是表格的示例屏幕截图,显示了拉动刷新控件时出现的难看的白色:
最佳答案
您必须使用 bgColor 创建一个 View ,并将其添加到 tableView 中,并将其添加到 tableView 中。
警告:
- 您必须将此 View 插入到 tableView subview 的底部堆栈
- 您必须在设置 refreshControll 后插入此 View :self.refreshControl = refreshControl;
如果您不以这种方式插入此 View ,您将看不到刷新控件:他将隐藏在您的 View 下方。
- (void)viewDidLoad
{
[super viewDidLoad];
// Background Color
UIColor *bgRefreshColor = [UIColor grayColor];
// Creating refresh control
refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[refreshControl setBackgroundColor:bgRefreshColor];
self.refreshControl = refreshControl;
// Creating view for extending background color
CGRect frame = self.tableView.bounds;
frame.origin.y = -frame.size.height;
UIView* bgView = [[UIView alloc] initWithFrame:frame];
bgView.backgroundColor = bgRefreshColor;
bgView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Adding the view below the refresh control
[self.tableView insertSubview:bgView atIndex:0]; // This has to be after self.refreshControl = refreshControl;
}
关于iphone - UIRefreshControl 背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13364465/