How to change UIButton image in Swift

前端 未结 12 1347
猫巷女王i
猫巷女王i 2020-12-01 00:25

I am trying to change the image of a UIButton using Swift... What should I do

This is OBJ-C code.but I don\'t know with Swift:

[playButton setImage:[         


        
12条回答
  •  情歌与酒
    2020-12-01 00:52

    For anyone using Assets.xcassets and Swift 3, it'd be like this (no need for .png)

    let buttonDone  = UIButton(type: .Custom)
    
    if let image = UIImage(named: "Done") {
        self.buttonDone.setImage(image, for: .normal)
    }
    

提交回复
热议问题