简体   繁体   中英

Xcode Editor PlaceHolder in source file

This is my code:

`import UIKit

class ViewController: UIViewController {

    var activePlayer = 1 //Cross


    @IBAction func action(_ sender: UIButton)
    {
        if (activePlayer == 1)
        {

//I always get an error around this part

sender.setImage(UIImage(named:"Cross.png"), for: UIControl.State()) } else { sender.setImage(UIImage(named:"Nought.png"), for: UIControl.State()) } }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

` Somebody please help me because I need to know., If it would be of help, I have inserted "Cross.png" into the project and inserted "Nought.png", but when why was writing that part of the code, It never reccomended me to put those names like as a suggestion.

Make sure to put the images in the Assets.xcassets folder. Then you will get the suggestions.

If that doesn't work make sure to save images in the Assets.xcassets folder and set image like:

ImageView.image = image

When you type in image, click on the suggestion which says image literal and double click on the picture icon. You should get access to all the images in the Assets.xcassets folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM