commit cad0bd7b0bce87dbf4db48dcf14592ebc42134bb
parent 99a5c225c83133091265fa254804e241f6d520eb
Author: Marc Stibane <marc@taler.net>
Date: Tue, 16 Sep 2025 17:34:02 +0000
Image+centerCropped
Diffstat:
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/TalerWallet1/Helper/Image+centerCropped.swift b/TalerWallet1/Helper/Image+centerCropped.swift
@@ -0,0 +1,36 @@
+/* MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Inspired by https://stackoverflow.com/users/1630618/vacawama
+ */
+import SwiftUI
+
+extension Image {
+ func centerCropped() -> some View {
+ GeometryReader { geo in
+ self
+ .resizable()
+ .scaledToFill()
+ .frame(width: geo.size.width, height: geo.size.height)
+ .clipped()
+ .contentShape(Rectangle())
+ }
+ }
+}