
- SwiftUI - Home
- SwiftUI - Overview
- SwiftUI vs UIkit
- SwiftUI Environment
- SwiftUI - Environment Setup
- SwiftUI - Basic Components
- SwiftUI - Building First Application
- SwiftUI Views
- SwiftUI - Views
- SwiftUI - Customize Text View
- SwiftUI - Custom Image View
- SwiftUI - Stacks
- SwiftUI Drawing Shapes
- SwiftUI - Shapes
- SwiftUI - Drawing line
- SwiftUI - Drawing Rectangle
- SwiftUI - Drawing Rounded Rectangle
- SwiftUI - Drawing Triangle
- SwiftUI - Drawing Circle
- SwiftUI - Drawing Star
- SwiftUI - Drawing Polygon
- SwiftUI - Drawing Pie chart
- SwiftUI - Using built-in shapes
- SwiftUI - Text
- SwiftUI - Text View
- SwiftUI - Text Input and Output
- SwiftUI - Color
- SwiftUI - Color
- SwiftUI - Colorpicker
- SwiftUI - Gradients
- SwiftUI - Adjust Color
- SwiftUI - Effects
- SwiftUI - Effects
- SwiftUI - Blend Effect
- SwiftUI - BLur Effect
- SwiftUI - Shadow Effect
- SwiftUI - Hover Effect
- SwiftUI - Animations
- SwiftUI - Animations
- SwiftUI - Creating Animations
- SwiftUI - Creating an Explicit Animation
- SwiftUI - Multiple Animations
- SwiftUI - Transitions
- SwiftUI - Asymmetric Transition
- SwiftUI - Custom Transition
- SwiftUI - Image
- SwiftUI - Images
- SwiftUI - Image as Background
- SwiftUI - Rotating Image
- SwiftUI - Media
- SwiftUI - View Layout
- SwiftUI - View Layout
- SwiftUI - View Size
- SwiftUI - View Spacing
- SwiftUI - View Padding
- SwiftUI - UI Controls
- SwiftUI - UI Controls
- SwiftUI - Button
- SwiftUI - CheckBox
- SwiftUI - Menubar
- SwiftUI - Toolbar
- SwiftUI - Search Bar
- SwiftUI - TextField
- SwiftUI - Slider
- SwiftUI - Toggle
- SwiftUI - Pickers
- SwiftUI - Menus
- SwiftUI - List & Tables
- SwiftUI - Lists
- SwiftUI - Static List
- SwiftUI - Dynamic List
- SwiftUI - Customize List
- SwiftUI - Tables
- SwiftUI - Forms
- SwiftUI - Forms
- SwiftUI - Breaking Forms in Sections
- SwiftUI - Event Handling
- SwiftUI - Event Handling
- SwiftUI - Gesture
- SwiftUI - Clipboard
- SwiftUI - Drag and Drop
- SwiftUI - Focus
- SwiftUI - Alert
- SwiftUI - Miscellaneous
- SwiftUI - Containers
- SwiftUI - Navigation
- SwiftUI - Notifications
- SwiftUI - Cross-Platform UI
- SwiftUI - Data
- SwiftUI - Accessibility
- SwiftUI - Framework Integration
- SwiftUI - Framework Integration
- SwiftUI - Interfacing with UIKit
- SwiftUI - Creating macOS App
- SwiftUI Useful Resources
- SwiftUI - Useful Resources
- SwiftUI - Discussion
SwiftUI - Customize Image View
Image view displays single or multiple images together on the screen. It is the most important view of SwiftUI. Using image view we can easily display images from the asset catalog. It can work easily with various image formats such as PNG, JPEG, PDF, etc. It can also work efficiently with SFSymbols.
Image view effortlessly manages and manipulates images to create more creative layouts. It also supports various modifiers to stretch, scale, resize, or pin images to a particular location. Image view can only display images it is not interactive.
Displaying Image using Image View in SwiftUI
Displaying an image using Image view is a very straightforward method we need to follow the following steps to display an image on the screen−
Step 1: Prepare Image
To display the image in the image view first we need to add the image inside the Assets.xcassets folder by dragging and dropping the image file.
Step 2: Add Image View
To add an image in the view, open ContentView.swift file then use Image view inside the body property. As we already placed the image inside the assets we pass the reference of the image inside the Image view. It reduces the risk of runtime errors happening due to incorrect image names. If any changes are made in the asset catalog, then it will notify in the code where the image is used as a reference so that you can change it before compiling the code.
struct ContentView: View { var body: some View { Image("imageName") } }
Step 3: Run the App
Run the app in the simulator or device to see the image.
Example
The following SwiftUI program is used to create an image view.
import SwiftUI struct ContentView: View { var body: some View { Image(.wallpaper) } } #Preview { ContentView() }
Output

Customize Image View in SwiftUI
By customizing the image view we can change the appearance and behavior of the image according to the design requirement with the help of various modifiers provided by SwiftUI. Using these modifiers we can change the shape, size, color, and other visual properties of the image view. SwiftUI provide various in-built modifiers to customize the image present in the Image view and some of the commonly used modifiers are as follows −
Modifiers | Description |
---|---|
frame(width:height:alignment:) | It is used to explicitly set the width and height of the image view. |
resizable() | It is used to resize images. |
aspectRation(contentMode:) | It is used to manage the aspect ratio of the image while resizing it. |
clipShape(RoundedRectangle(cornerRadius:)) | It is used to round the corners of the image view. This modifier is also used to change the shape of the image. |
padding() | It is used to insert space around the image view |
Image(systemName:"SymbolName") | It is used to display SF Symbol. | shadow(radius) | It is used to apply a shadow effect on the image view. | overlay() | It is used to overlay another view on top of the image. | opacity() | It is used to set the opacity of the image view. |
Example
The following SwiftUI program is used to customize image view.
import SwiftUI struct ContentView: View { var body: some View { VStack{ Image(.wallpaper) .resizable() .frame(width: 300, height: 200) Image(.wallpaper) .resizable() .frame(width: 300, height: 200) .clipShape(Capsule()) Image(.wallpaper) .resizable() .frame(width: 300, height: 200) .shadow(radius: 30) .opacity(0.7) Image(systemName: "star") .frame(width: 300, height: 200) .font(.largeTitle) } } } #Preview { ContentView() }
Output
