user3708335 user3708335 - 1 month ago 10
Swift Question

Defining the file a UIImage will use (Swift)

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.

Answer

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")