SwiftUI Overlay the image on the image at any position
SwiftUI Overlay the image on the image at any position
Category:iOS
Pub.date:2021-03-22
Overlay the image on the image at any position with Swift UI.
Overlay an image of 90 pixels in height and width on an image of 900 pixels in height and width at an arbitrary position
Swift 5.3.2
Xcode 12.4
iOS Target 14.4
macOS 11.2.3 BigSur
Example
struct ContentView: View {
@State private var imageOne: String = "imageOne"
@State private var imageTwo: String = "imageTwo"
@State private var imageTwoPosition: CGPoint = CGPoint(x: 0, y: 0)
var body: some View {
NavigationView {
Image(self.imageOne)
.resizable()
.frame(width: bodyView.size.width, height: bodyView.size.width, alignment: .center)
.overlay(
Image(self.imageTwo)
.resizable()
.frame(width: bodyView.size.width / 10, height: bodyView.size.width / 10, alignment: .center)
.position(x: bodyView.size.width * self.imageTwoPosition.x / 900, y: bodyView.size.width * self.imageTwoPosition.y / 900)
)
}
}
}
An image of 900 pixels in height and width is displayed to the full width of the screen.
An image of 90 pixels vertically and horizontally is superimposed on it at an arbitrary position.
imageOne
imageTwo
imageTwoPosition
These can be dynamically replaced or their values can be changed.
Of course, if the size is different, adjust accordingly.
CONTENTS
JavaScript
Unreal Engine
CakePHP4
CakePHP4
Flutter
Flutter
Other
JavaScript
JavaScript
CakePHP4
Web Server
Photoshop
Unreal Engine
CakePHP4
Web Browser
Web Server
iOS
Android
Web Browser
CakePHP4
Plesk
Illustrator
Plesk
Web Server
Web Server
CakePHP3
Web Browser
CakePHP3
JavaScript
JavaScript
CakePHP3
CakePHP3