1

I am new to programming.

@IBOutlet weak var myView: UIView!

var l: CALayer { 
    return myView.layer
    }

override func viewDidLoad() {
    super.viewDidLoad()
    setUpLayer()
}

func setUpLayer() {
    l.contents = UIImage(named: "IMG_3682.jpg")?.CGImage
    l.contentsGravity = kCAGravityCenter
}

The image appears way bigger than myView.

I got imges with various sizes and ratios. and I want to fit them into UIView.layer What is the right way to do it?

thanks

Kyle KIM
  • 1,384
  • 2
  • 15
  • 31

1 Answers1

0

Remove line:

l.contentsGravity = kCAGravityCenter
Frankenstein
  • 15,732
  • 4
  • 22
  • 47