我有24个gif文件,当我想通过计数器编程Next按钮时,它从gif编号11开始,我希望从01开始,所以从字面上看它跳过前10个GIF!
var counter = 0
@IBOutlet weak var image: UIImageView!
@IBAction func next(_ sender: Any) {
image.image = UIImage (named: "frame_\(counter)_delay-0.06s.gif")
counter += 1
if counter == 24 {
counter = 0
}
}
答案 0 :(得分:0)
您可以使用String(format: "frame_%02d_delay-0.06s.gif",counter)
所以你将拥有以下代码,
let imageName = String(format: "frame_%02d_delay-0.06s.gif",counter)
image.image = UIImage (named: imageName)