-2

In Objective C I was using this code to scale an image to my background. How can I achieve this in Swift.

path = [[NSBundle mainBundle] pathForResource:@"This" ofType:@"png"];
image = [[UIImage alloc] initWithContentsOfFile:path];
hata
  • 11,633
  • 6
  • 46
  • 69
Dave
  • 27
  • Have you tried Google? First result: http://nshipster.com/image-resizing/ and even a result on StackOverflow http://stackoverflow.com/questions/27153181/how-do-you-make-a-background-image-scale-to-screen-size-in-swift – Tyler StandishMan Sep 25 '15 at 14:15
  • Had been able to do this with a UIView but thanks to your reference going to a UIImageView was the start of the understanding. – Dave Sep 25 '15 at 16:27

1 Answers1

2

you can try this:

path = NSBundle.mainBundle().pathForResource("This", ofType: "png")
image = UIImage(contentsOfFile: path)
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • Thank you it worked. Changing from a UIView to UIImageView allowed setting .ScaleToFill. – Dave Sep 25 '15 at 16:29