Home>
var Datalist: Int = 2
    override func viewDidLoad () {
        super.viewDidLoad ()
            print (Datalist)
        if Datalist == 2 {
            self.view.backgroundColor = UIColor (patternImage: UIImage (named: "nighthanabi")!)
        }
        else {self.view.backgroundColor = UIColor (patternImage: UIImage (named: "vacation")!)
        }


If i make the nighthanabi part of this code a different file (0x1276d8e38). One of the two will be used. Which one is undefined.
I thought the photo file was big, but I made it small, but it wasn't.
This part changes the background photo depending on the picker selection.

The screen transitions to the one that changes the background of the above one with this code.
What should I do? Thank you for teaching me.

var Datalist: Int = 2
    override func viewDidLoad () {
        super.viewDidLoad ()
            print (Datalist)
        if Datalist == 2 {
            self.view.backgroundColor = UIColor (patternImage: UIImage (named: "beautiful")!)
        }
        else {self.view.
  • Answer # 1

    Now I prepared two types of images,.jpgand.pngcode>was not displayed. So please describe the String to be included inUIImage (named:)with the extension. Then it will be displayed.

    UIImage (named: "beautiful.jpg")

    By the way,.pngdidn't need an extension.

    (Added)
    The reason is a mystery. I would be happy to tell you if you know.

    (Additional notes)
    Based on information from>>yukihisa

    It seems that the extension can be omitted only for

    .png.
    Source

    Thank you for the information!

Related articles