图像名称作为变量(Swift)

时间:2016-07-07 10:11:41

标签: ios iphone swift variables func

我试图调用下面的func,我应该在loadImage()中写什么,以便每当我调用它时我都可以输入不同的图像名称。

非常感谢

func loadImage(????){

        self.Picture.image = UIImage (named: "Ch1-4 new.jpg")

              UIView.animateWithDuration(3.0,
                                   delay: 0.0,
                                   options: [],
                                   animations : {

                                    let message = "Picture.mp3"
                                    let triggerTime = (Int64(NSEC_PER_SEC) * 1)
                                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, triggerTime), dispatch_get_main_queue(), { () -> Void in
                                        self.playMessageOpening(message)
                                    })
                                    self.Picture.hidden=false
                                    self.Picture.alpha=0.0;
                                    self.Picture.alpha=1.0;

            },
                                   completion: { finished in
                                    print("Picutre done")


        })
    }

1 个答案:

答案 0 :(得分:3)

func loadImage(imageName: String) {
    self.Picture.image = UIImage (named: imageName)

    ...
}

其中imageName是参数的名称,String是类型。有关the Apple docs中的函数声明的更多信息。