43

So I looked around the developer library on apple's site and I couldn't find any documentation that said how to state what file (like a png) to use for a UIImage using the swift language. So I try experimenting with this code:

class ViewController: UIViewController {

@IBOutlet var maintitle: UIImageView

var bigtitle: UIImage!
var smalltitle: UIImage!


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

    func startAnimating(){
        var animatedtitle: AnyObject[] = [bigtitle, smalltitle]
        var animationDuration: NSTimeInterval = 0.15
        var animationRepeatCount: Int = 0
    }
}

What I was trying to do there was animate a never ending series of two images. I defined two UIImages (bigtitle & small title) and was wondering how I define wat .png's to use for those UIImage's. I know this is a very basic and novice question but any help would be enjoyed.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3708335
  • 479
  • 1
  • 5
  • 7

1 Answers1

126

Even though you are using Swift, all the classes that come from UIKit and other libraries still are written in Objective-C.

There is no difference in the interfaces to these libraries, just the syntax.

In this case, you need to use the object construction syntax:

var image = UIImage(named:"ImageName")
saurabh
  • 6,687
  • 7
  • 42
  • 63
Jack
  • 16,677
  • 8
  • 47
  • 51