skip to Main Content

When using the standard UIRefreshControl in TableView the swipe down can be too long, that is, I have to drag my finger almost to the very bottom of the screen.

Is it possible to shorten the swipe path?

var refreshControl = UIRefreshControl()

 @objc func refresh(_ sender: AnyObject) {
    // Refresh anything
 }

 override func viewDidLoad() {
    super.viewDidLoad()
    
    refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
    refreshControl.backgroundColor = UIColor.clear
    TableView.addSubview(refreshControl) 
    
    refresh(view)
 }

Thank you in advance for your help.

2

Answers


  1. Try it.

        refreshControl.addTarget(self, action: #selector(refreshHande(_:)), for: .valueChanged)
        let ori = tableView.frame
        let temp_frame = CGRect.init(x: ori.origin.x, y: ori.origin.y, width:
        ori.size.width, height: ori.size.height/1.3 )
        tableView.frame = temp_frame
        tableView.addSubview(refreshControl)
        tableView.frame = ori
    
    Login or Signup to reply.
  2. TableView has property refreshControl. Use the following code

    var refreshControl = UIRefreshControl()
    
     @objc func refresh(_ sender: AnyObject) {
        // Refresh anything
     }
    
     override func viewDidLoad() {
        super.viewDidLoad()
        
        refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
        refreshControl.backgroundColor = UIColor.clear
    
        // tableView is a UITableView outlet 
        tableView.refreshControl = refreshControl
        
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search