UIRefreshControl背景颜色 [英] UIRefreshControl Background Color

查看:132
本文介绍了UIRefreshControl背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to make the background of a UIRefreshControl grow as the control grows?

我想为刷新控件设置彩色背景以匹配顶部细胞的背景颜色。更改tableview的背景颜色是不可接受的,因为底部的空单元格也会有颜色,但我需要它们保持白色。

I would like to have a colored background for the refresh control to match the top cell's background color. Changing the background color of the tableview is not acceptable because then empty cells at the bottom will also have the color, but I need them to stay white.

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

Apple's mail app shows this behavior. The refresh control's background matches the gray search bar, but empty cells at the bottom of the table view are still the normal white.

以下是表格外观的示例屏幕截图显示刷新控件被拉出时出现的丑陋白色:

Here's an example screenshot of how the table looks showing the ugly white that appears as the refresh control is pulled:

推荐答案

您必须使用bgColor创建一个视图,并在tableView中添加负y原点。

You have to create a view with the bgColor and adding it with negative y origin in the tableView.

警告:


  • 您必须在tableView子视图的底部堆栈中插入此视图

  • 您必须在设置refreshControll后插入此视图:self.refreshControl = refreshControl;

如果您不要以这种方式插入此视图,您将看不到刷新控件:他将隐藏在您的视图下方。

If you do not insert this view this way you will not see the refresh control: he will be hidden below your 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;
}

这篇关于UIRefreshControl背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆