ImageView insect in iOS swift || Imageview with space in all sides iOS
Problem:
I want to create an imageView with image and it will not be filled with imageView.
It wants to be like four sides wants to be few space needed to show.
So i tried to give imageview.contentmode = .center
But it shows that more space came in imageview but image is in small in center of imageview
After that i had tried to give border color but it also a bad solution for that.
How can i achieve that?
Solution:
extension UIImage {
func imageInsets(insets: UIEdgeInsets) -> UIImage? {
UIGraphicsBeginImageContextWit
CGSize(width: self.size.width + insets.left + insets.right,
height: self.size.height + insets.top + insets.bottom), false, self.scale)
let _ = UIGraphicsGetCurrentContext()
let origin = CGPoint(x: insets.left, y: insets.top)
self.draw(at: origin)
let imageInsets = UIGraphicsGetImageFromCurrentI
UIGraphicsEndImageContext()
return imageInsets
}
}
added the extension for image in extension file and used as like below.
imgView.image = imgView.image!.imageInsets(i
Comments
Post a Comment