iphone - UIRefreshControl 背景色

标签 iphone objective-c ios uirefreshcontrol

是否可以使 UIRefreshControl 的背景随着控件的增长而增长?

我希望刷新控件的背景颜色与顶部单元格的背景颜色相匹配。更改 tableview 的背景颜色是 Not Acceptable ,因为底部的空单元格也会有颜色,但我需要它们保持白色。

Apple 的邮件应用程序显示了此行为。刷新控件的背景与灰色搜索栏相匹配,但表格 View 底部的空单元格仍然是正常的白色。

下面是表格的示例屏幕截图,显示了拉动刷新控件时出现的难看的白色:
enter image description here

最佳答案

您必须使用 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/

相关文章:

iphone - 将刷新 UIBarButtonItem 添加到从 NIB 加载的 UINavigationController

ios - 第一次加载时不显示按钮文本

objective-c - 如何 TDD UIGestureRecognizers?

ios - 了解 UITableView dequeueReusableCellWithIdentifier - 即使在第一次调用时也返回单元格

ios - Swift 中的可选参数标识符

ios - sendResourceAtURL 多端 IOS7

iphone - 为 iOS Developer Enterprise Program 中的其他公司构建的临时测试

iphone - 按两次主页按钮时 iPhone 中的应用程序关闭通知

javascript - HTML 5 Panotour Pro 实现

ios - 如何解决内存崩溃