Set UIImageView Image Inset for iOS and iPadOS app.

Here is an example if you want to inset UIImageView so that the image does not fit edge to edge of the UIImageView

Note:
The latest version of Xcode & Latest version of Swift Programming Language is preferred.

Here is step by step procedure to achieve the designed result:

Step 01:
Create Apple iOS Project in Xcode. Add UIImageView to View Controller in Storyboard.

Step 02:
Now Connect that UIImageView to the View Controller Swift File. It will look something like this.

@IBOutlet weak var imageView: UIImageView!

Step 03:
Now add the following code in the ViewDidLoad Function of your View Controller File.

// Scale & Aspect Fill Image to UIImageView
imageView.contentMode = .scaleAspectFill

// Now assign image from asset catalogue & inset image
imageView.image = UIImage(named: "image-name")?.withAlignmentRectInsets(UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10))

Result:
It would help if you got the desired result with an image with an inset.

Hope it helps,

Thanks & Regards
Mandar Apte

Published by Mandar Apte

Mandar is a Mumbai-based multi-disciplinary designer with UX/UI, Logo, Symbol, and Brand Identity design expertise. He currently runs his Mudrkashar Linguistic Apple iPhone, iPad, and Mac app business in the heart of Mumbai city.

Leave a comment

Leave a Reply