UIRefreshControl背景颜色(UIRefreshControl Background C

2019-08-02 17:16发布

是否有可能使一个UIRefreshControl的背景下成长为控制增长?

我想有刷新控制,以配合顶部单元格背景颜色的彩色背景。 改变的tableview的背景颜色是不能接受的,因为那时空单元格的底部也会有颜色,但我需要他们留下白色。

苹果的邮件应用程序显示了这种行为。 刷新控制的背景灰色搜索栏比赛,但空单元格表格视图的底部仍然是正常的白色。

下面是表的外观表示作为刷新控制被拉出现的丑陋白色的示例屏幕截图:

Answer 1:

你必须创建具有BGCOLOR一个视图,并在负的tableView y原点添加。

警告:

  • 你必须在子视图的tableView的底部堆插入此观点
  • 您可以设置refreshControll后插入这样的观点:self.refreshControl = refreshControl;

如果你不这样插入这个观点,你不会看到更新控制:他将被隐藏您的视图下方。

- (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;
}


Answer 2:

斯威夫特的版本更容易的复制粘贴:)

斯威夫特2

func viewDidLoad() {
    super.viewDidLoad()

    // Background Color
    let backgroundColor = UIColor.grayColor()

    // Creating refresh control
    let refresh = UIRefreshControl()
    refresh!.backgroundColor = backgroundColor
    refresh!.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
    refreshControl = refresh

    // Creating view for extending background color
    var frame = tableView.bounds
    frame.origin.y = -frame.size.height
    let backgroundView = UIView(frame: frame)
    backgroundView.autoresizingMask = .FlexibleWidth
    backgroundView.backgroundColor = backgroundColor

    // Adding the view below the refresh control
    tableView.insertSubview(backgroundView, atIndex: 0) // This has to be after refreshControl = refresh
}

斯威夫特3

func viewDidLoad() {
    super.viewDidLoad()

    // Background Color
    let backgroundColor = .gray

    // Creating refresh control
    let refresh = UIRefreshControl()
    refresh!.backgroundColor = backgroundColor
    refresh!.addTarget(self, action: #selector(refresh), forControlEvents: .valueChanged)
    refreshControl = refresh

    // Creating view for extending background color
    var frame = tableView.bounds
    frame.origin.y = -frame.size.height
    let backgroundView = UIView(frame: frame)
    backgroundView.autoresizingMask = .flexibleWidth
    backgroundView.backgroundColor = backgroundColor

    // Adding the view below the refresh control
    tableView.insertSubview(backgroundView, atIndex: 0) // This has to be after refreshControl = refresh
}


文章来源: UIRefreshControl Background Color