Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining the file a UIImage will use (Swift)

Tags:

ios

swift

uiimage

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.

like image 361
user3708335 Avatar asked Jun 04 '14 23:06

user3708335


People also ask

What is UIImage Swift?

An object that manages image data in your app.

How do you declare UIImage in Objective C?

For example: UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]]; My UIImage object is declared in .

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

How do I find my UIImage path?

Once a UIImage is created, the image data is loaded into memory and no longer connected to the file on disk. As such, the file can be deleted or modified without consequence to the UIImage and there is no way of getting the source path from a UIImage.


1 Answers

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") 
like image 71
Jack Avatar answered Oct 14 '22 11:10

Jack