/ / Sostituisci UIRefreshControl con UIImageView - ios, swift, uitableview, uiimageview, uirefreshcontrol

Sostituisci UIRefreshControl con UIImageView - ios, swift, uitableview, uiimageview, uirefreshcontrol

Ho un UIRefreshControl nel mio UITableView. Voglio sostituire l'icona di aggiornamento del sistema con la mia. Ho provato ad aggiungere una sottoview a refreshControl in questo modo ...

    let refreshImage = UIImageView()
refreshImage.image = UIImage(named: "RefreshIcon")
refreshControl.insertSubview(refreshImage, at: 0)
tableview.addSubview(refreshControl)

Ma quello non ha funzionato. Qualcuno ha qualche idea? Molte grazie!

risposte:

1 per risposta № 1

Per favore prova questo codice:

 let refreshImage = UIImageView()
refreshImage.image = UIImage(named: "RefreshIcon")
refreshControl.backgroundColor = UIColor.clear
refreshControl.tintColor = UIColor.clear
refreshControl.addSubview(refreshImage)
tableview.addSubview(refreshControl)

e quindi per centrarlo in alto, puoi usare questo:

    refreshImage.frame = refreshControl.bounds.offsetBy(dx: self.view.frame.size.width / 2 - 20 // half the width of the refreshImage, dy: 10)
refreshImage.frame.size.width = 40 // Whatever width you want
refreshImage.frame.size.height = 40 // Whatever height you want