Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

ios - 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.

question from:https://stackoverflow.com/questions/24049537/defining-the-file-a-uiimage-will-use-swift

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...