티스토리 뷰

우선 사용하고자 하는 뷰의 뷰컨트롤러에  



    lazy var refreshControl: UIRefreshControl = {

        let refreshControl = UIRefreshControl()

        refreshControl.addTarget(self, action:

            #selector(handleRefresh(_:)),

                                 for: UIControlEvents.valueChanged)

        refreshControl.tintColor = UIColor.red

        

        return refreshControl

    }()



구문을 선언해 준다. ( 빙글빙글 돌아가는 indicator 추가 )


그리고 뷰에 추가시켜 준다. 



        scrollSuperView.addSubview(self.refreshControl)


나의 경우에는 스크롤 뷰를 내리면 리로드 시키고 싶어서 

스크롤 뷰에 추가시켜 주었다. 



    @objc func handleRefresh(_ refreshControl: UIRefreshControl) {

        

       // 이부분에 하고싶은 action 추가 해주면 됩니당. 


        

        refreshControl.endRefreshing()

    }


위의 함수는 refreshControl 선언시 타겟 액션 을 걸어준 함수이기 때문에 , 화면을 당겨서 내릴 경우마다 위의 함수가 실행되므로 , 

handleRefresh 함수 안에 하고자 하는 액션을 추가하면 , 쉽게 구현할 수 있당.


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday