swift 2.0 how to get the image of loaded as background on the screen at this point



  • swift 2.0 as to get the image of the loaded background_ on the screen

    import UIKit import Foundation

    class ViewController: UIViewController {

    var startTimer0003: NSTimer!       //background первичный запуск
    weak var startTimer0004: NSTimer!  //backgraund интервалы повторов
    

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    self.startTimer0003 = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "runMe0002",userInfo:nil,repeats: false) 
    //background первый запуск
    
    self.startTimer0004 = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "runMe0002",userInfo:nil,repeats: true)
    //background интервал повтора
    

    }

    /*************************************************************/
    // xCode марки 7.2
    // запуск на iPhone 6+

    /********************** background *************************/

    weak var imBackGroundView: UIImageView?

    func runMe0002() {

    if(self.imBackGroundView == nil)
    
    {
    
        self.view.backgroundColor = UIColor(patternImage: UIImage(named:
        background[0])!)
        //background = массив тип String, для проверки берется только одно [0] значение
    
    }
    
    let imageBackground = UIImage.init(named: background[0]) // все значения для пробы на отклик
    let imageBackground0002 = self.view.backgroundColor!
    let image0002 = UIImage.init(named: background[0])      
    //  let image0002 = UIImage.init(named: "bk0002.jpg") //проба по значению image 
    let imageBackGroundColor = UIImage.init(named: background[0])
    

    /*********************** switch *******************************************/
    switch (self.view.backgroundColor)! // или проба из списка откомментированных = все одинаково...
    // switch (UIColor(patternImage: UIImage(named: background[0])!))
    // switch (self.view.backgroundColor! = UIColor(pattertnImage: UIImage(named: background[0]))!)

    {
        // 0
    case (self.view.backgroundColor)! === image0002:
        print("view.backgroundColor works_0")
        //0.1
    case self.view.backgroundColor! !== UIImage!(imageBackground!):
        print("view.backgroundColor works_0.1")
        //0.2
    case self.view.backgroundColor! !== UIColor(patternImage: (UIImage?(imageBackground!)!)!):
        print("view.backgroundColor works_0.2")
        //0.3
    case imageBackGroundColor !== "bk0002.jpg":
        print("It works_0.3")
        //0.4
    case image0002! :
        print("It works_0.4")
        //0.5
    case UIColor(patternImage: (UIImage?(imageBackground!)!)!):
        print("It works_0.5")
        //0.6
    case "bk0002.jpg":
        print("It works_0.6")
        //0.7
        //case background[0]: ОШ String
        //   print("It works_0.7")
        //0.8
    case UIColor(patternImage: (UIImage?(imageBackground!)!)!):
        print("It works_0.8")
        //0.9
    case UIColor(patternImage: UIImage(named: background[0])!):
        print("It works_0.9")
    
        // 1
    case self.view.backgroundColor! != background[0]:
        print("view.backgroundColor works_1")
        // 2.0
    case self.view.backgroundColor! !== UIImage(named: background[0]):
        print("view.backgroundColor works_2.0")
        // 2.1
    case self.view.backgroundColor! !== UIImage.init(named: background[0]):
        print("view.backgroundColor works_2.1")
        // 2.2
    case UIColor(patternImage: UIImage(named: background[0])!) != background[0]: //"bk0002.jpg":
        print("view.backgroundColor works_2.2")
        // 2.3
    case self.view.backgroundColor! !== UIColor(patternImage: UIImage(named: "bk0002@3x.jpg")!):
        print("view.backgroundColor works_2.3")
        // 3
    case self.view.backgroundColor! !== UIColor(patternImage: UIImage(named: background[0])!):
        print("view.backgroundColor works_3")
        // 4
    case UIColor(patternImage: UIImage(named: background[0])!) !== true:
        print("view.backgroundColor works_4")
        // 5
    case UIColor(patternImage: UIImage(named: background[0])!) !== 0:
        print("view.backgroundColor works_5")
        // 6
    case UIColor(patternImage: UIImage(named: background[0])!) !== "bk0002.jpg":
        print("view.backgroundColor works_6")
        // 7
    case UIColor(patternImage: UIImage(named: background[0])!) !== "bk0002@3x.jpg":
        print("view.backgroundColor works_7")
        // 8
    case self.view.backgroundColor! != UIImage(named: "bk0002@3x.jpg")!:
        print("view.backgroundColor works_8")
        // 9
    case imBackGroundView == background[0]:
        print("view.backgroundColor works_9")
        // 9.1
    case self.imBackGroundView != background[0]:
        print("view.backgroundColor works_9.1")
    
        // 10
    case self.imBackGroundView != UIImage(named: background[0]):
        print("view.backgroundColor works_10")
        // 11
    case self.imBackGroundView === UIColor(patternImage: UIImage(named: background[0])!):
        print("view.backgroundColor works_11")
        // 12
    case self.imBackGroundView === UIImage(named: "bk0002.jpg"):
        print("view.backgroundColor works_12")
        // 13
    case self.imBackGroundView !== self.view.backgroundColor:
        print("view.backgroundColor works_13")
        // 14
    case self.imBackGroundView !== UIColor(patternImage: UIImage(named:
        background[Int(arc4random_uniform(UInt32(background.count)))])!):
        print("view.backgroundColor works_14")
        // 15.0
        // case self.view.backgroundColor!.isEqual(UIColor(patternImage: UIImage?(named: image0002))):
    case self.view.backgroundColor!.isEqual(UIColor(patternImage: (UIImage!(image0002))!)):
        print("view.backgroundColor works_15.0")
        // 15.1
    case self.view.backgroundColor!.isEqual(UIColor(patternImage: (UIImage.init(named: background[0]))!)):
        print("view.backgroundColor works_15.1")
        // 15.2
        // case (UIColor(patternImage: UIImage(named: background[0]))!) isEqual image0002: // = ОШ
        //   print("view.backgroundColor works_15.2")
    
        // 16
        //case self.view.backgroundColor?.isEqual (UIColor(patternImage: (UIImage!(named: background[0]))!)):            
        //case self.view.backgroundColor!.isEqual(UIColor!(patternImage: UIImage!(named: "bk0002.jpg"))!):            
        //case self.view.backgroundColor!.isEqual(UIColor(patternImage: (UIImage!("bk0002@3x.jpg"))!)):
    
        //      print("view.backgroundColor works_16")
    
    default :  print("view.backgroundColor no result") // все принт идут в консоль...
    
    }   //скобка  закрытия  switch первый
    
    
    
    /***********************    **************************/
    
    startTimer0003.invalidate()
    
    // startTimer0004.invalidate()
    

    } // скобка func runME0002

    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    }

    } // commit - reference to ya.disk


    weak var imBackGroundView: UIImageView? // = imageBackground

    func runMe0002() {

    var imageBackground = UIImage(named: background[Int(arc4random_uniform(UInt32(background.count)))])

    if imageBackground! != UIImage(named: background[0])            
    {
    print("imageBackground works_0") }
    
    else { print("view.backgroundColor no result")        
    }   //скобка  закрытия  if
    
    if(self.imBackGroundView == nil)           
    {            
        self.view.backgroundColor = UIColor(patternImage: UIImage!(imageBackground))            
    } //скобка if (self.imBackGroundView == nil)
    

    } // bracket func runMe0002()



  • No standard function. And if the image is displayed, the name of the file cannot be obtained, plus not the fact that the image from the file can be downloaded from the network.

    But you can create a variable and keep in the name of the file you take. You can create your class inherited from UIImage and in the classroom, name the file.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2