when i set background image as pattern image then image is stretch so, i want to set as aspect-fit this pattern image so, how can do this?
let Image1 = UIImage(named: KeyboardBG_image)
UIGraphicsBeginImageContext(keyboardview.frame.size);
Image1?.draw(in: keyboardview.bounds);
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = UIColor(patternImage: image!)
Thanks..
There is a method in
AVFoundation
that might help you create an image in a particular size rect while keeping the aspect ratio. This will calculate the rect size based on the size that you provide, I used a maximum height since the original image is a landscape image.