ios 定义 UIImage 将使用的文件 (Swift)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24049537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Defining the file a UIImage will use (Swift)
提问by user3708335
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:
因此,我环顾了苹果网站上的开发人员库,但找不到任何说明如何使用 swift 语言说明用于 UIImage 的文件(如 png)的文档。所以我尝试尝试使用以下代码:
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.
我试图做的是动画一个永无止境的两个图像系列。我定义了两个 UIImages(大标题和小标题)并且想知道我如何定义用于那些 UIImage 的 wat .png。我知道这是一个非常基本和新手的问题,但会得到任何帮助。
回答by Hyman
Even though you are using Swift, all the classes that come from UIKit
and other libraries still are written in Objective-C.
即使您使用的是 Swift,来自UIKit
其他库的所有类仍然是用 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")