前言:
之前練習所寫的模擬進度圈,採用圖片輪播
正文:
先製作圖片
再導入圖片到 Assets.xcassets 後
可以用陣列來輪播
接著計數時間跳轉頁面
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var ConnectProgressRateImage: UIImageView!
@IBOutlet weak var countLabel: UILabel!
let imgArr = [
UIImage(named:"circle1")!,
UIImage(named:"circle2")!,
UIImage(named:"circle3")!,
UIImage(named:"circle4")!,
UIImage(named:"circle5")!,
UIImage(named:"circle6")!,
UIImage(named:"circle7")!,
UIImage(named:"circle8")!,
UIImage(named:"circle9")!,
UIImage(named:"circle10")!,
UIImage(named:"circle11")!,
UIImage(named:"circle12")!,
UIImage(named:"circle13")!,
UIImage(named:"circle14")!,
UIImage(named:"circle15")!,
UIImage(named:"circle16")!,]
//計數跳轉頁面
var countValue = 0
var countInt = 1
override func viewDidLoad() {
super.viewDidLoad()
imageChange()
}
override func viewDidAppear(_ animated: Bool) {
countLoop()
DispatchQueue.main.async { [self] in
countLabel.reloadInputViews()
}
}
func countLoop(){
for _ in 0...100{
usleep(100000)
if countValue != 100 {
countValue += 1
countLabel.text = "\(countValue)%"
print("\(String(describing: countLabel))")
}
countLabel.setNeedsDisplay()
}
performSegue(withIdentifier: "GOSecondVC", sender: nil)
}
func imageChange() {
// 設置要輪播的圖片陣列
ConnectProgressRateImage.animationImages = imgArr
// 輪播一次的總秒數
ConnectProgressRateImage.animationDuration = 1
// 要輪播幾次 (設置 0 則為無限次)
ConnectProgressRateImage.animationRepeatCount = 9
// 開始輪播
ConnectProgressRateImage.startAnimating()
}
}
預覽圖: