Search code examples
iosobjective-cswiftuirefreshcontrol

UIRefreshControl styling - Swift iOS7+


How can you change the appearance of the UIRefreshControl to the "raindrop" style? I looked up the docs and it doesn't seem to have any appearance related options, although it inherits UIView/UIControl.

Also it's not centered in the tableview. I tried to align it by assigning a frame with x=0, but that didn't change it to left align. Here is what it looks like

UIRefreshControl out of place

And this is my code:

// in class description
var refreshControl: UIRefreshControl!

// in viewDidLoad()
refreshControl = UIRefreshControl()
//refreshControl.frame(CGRectMake(0, 0, 100, 100))
refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
tableView.addSubView(refreshControl)

func refresh(sender: AnyObject){
  println("refreshing")
refreshControl.endRefreshing()
}

Solution

  • You cannot change it to the "raindrop" style. This was appearance of refresh control when Apple introduced it in UIKit (back in iOS 6) but then they switched to the current one. In fact there is almost no customization you can do with the built-in UIRefreshControl - just some basic text styling and color.

    If you need more flexible control you either need to lookup 3rd party refresh controls or write something yourself.