Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Created August 11, 2023 21:43
Show Gist options
  • Save chockenberry/82f1640a8b74f594712e2939593879f0 to your computer and use it in GitHub Desktop.
Save chockenberry/82f1640a8b74f594712e2939593879f0 to your computer and use it in GitHub Desktop.
A struggle to resize an Image in an HStack
//
// ContentView.swift
// PanelTest
//
// Created by Craig Hockenberry on 8/11/23.
//
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
HStack {
Text("Header Text")
Spacer()
Image("checkmark") // this is a 170 x 170 px image
.resizable()
.aspectRatio(contentMode: .fit)
// NOTE: The image should adapt to the size of the Text() in this
// HStack(). This is because this needs to look right on iOS and tvOS.
//
// These are things that don't work:
//
// .frame()
// UIFontMetrics.default.scaledValue(for: value))
// @ScaledMetric
// GeometryReader
}
.padding(10)
.background(.orange)
.frame(maxWidth: .infinity)
Text("This is some body text")
.padding(10)
}
.background(.pink)
.frame(maxWidth: 300)
}
}
#Preview {
ContentView()
}
@chockenberry
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment