Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show scrollbar in UITableView before the table is dragged down. In a Way, the UIScrollBar should always be visible

In a I am using several UITableView in my app. Some of them contain several rows, while some have two three only. What I need is: if the table contains several rows, then the scrollbar should be visible before the user even drags the table down. Or in another way, is it possible to make scrollbar visible always??

like image 995
Shradha Avatar asked Mar 25 '14 04:03

Shradha


2 Answers

Swift 3.0

1) Timer

var timerForShowScrollIndicator: Timer?

2) Methods

/// Show always scroll indicator in table view
func showScrollIndicatorsInContacts() {
    UIView.animate(withDuration: 0.001) {
        self.tableView.flashScrollIndicators()
    }
}

/// Start timer for always show scroll indicator in table view
func startTimerForShowScrollIndicator() {
    self.timerForShowScrollIndicator = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(self.showScrollIndicatorsInContacts), userInfo: nil, repeats: true)
}

/// Stop timer for always show scroll indicator in table view
func stopTimerForShowScrollIndicator() {
    self.timerForShowScrollIndicator?.invalidate()
    self.timerForShowScrollIndicator = nil
}

3) Use

startTimerForShowScrollIndicator in viewDidAppear

stopTimerForShowScrollIndicator in viewDidDisappear

like image 51
ZAV Avatar answered Oct 23 '22 08:10

ZAV


    var timerForIndicatore:Timer?
           
    override func viewDidAppear(_ animated: Bool) {
                super.viewDidAppear(animated)
                
                showIndicator()
            }
            
         
       override func viewDidDisappear(_ animated: Bool) {
                super.viewDidDisappear(animated)
                
                deinitializeIndicator()
            }


 @objc func startContinuosShowingIndicator() {
        UIView.animate(withDuration: 0.0001) {
            self.deviceListTableView.flashScrollIndicators()
        }
    }

    func showIndicator() {
        self.timerForIndicatore = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(self.startContinuosShowingIndicator), userInfo: nil, repeats: true)
    }

    func deinitializeIndicator() {
        self.timerForIndicatore?.invalidate()
        self.timerForIndicatore = nil
    }
like image 43
Yudhisther Aryan Avatar answered Oct 23 '22 08:10

Yudhisther Aryan