Is it possible to make the background of a UIRefreshControl grow as the control grows?
I would like to have a colored background for the refresh control to match the top
Swift version for easier copy-pasting :)
Swift 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
}
Swift 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
}