Questions tagged [geometryreader]

A container view that defines its content as a function of its own size and coordinate space. Returns a flexible preferred size to its parent layout.

It's a component of Apple's SwiftUI language.

Learn more from Apple's documentation

184 questions
3
votes
0 answers

Set proportional width in SwiftUI

I've developed this component in SwiftUI: let rows: [RowModel] = [RowModel(type: "single", field: "single line field", value: "Value 1"), RowModel(type:…
Wonton
  • 1,033
  • 16
  • 33
3
votes
2 answers

Additional safe area on NavigationView in SwiftUI

I am building a SwiftUI app where I have an overlay that is conditionally shown across my entire application like this: @main struct MyApp: App { var body: some Scene { WindowGroup { NavigationView { …
3
votes
0 answers

SwiftUI: set cell view height from cell not working if using GeometryReader?

I have the following code: struct TestListView: View { var body: some View { Text("the list view") VStack { List { ForEach(0..<10) { n in CellView(number: n) …
zumzum
  • 17,984
  • 26
  • 111
  • 172
3
votes
2 answers

How can we make a Custom GeometryReader in SwiftUI?

I was wondering how GeometryReader works under cover, and I am interested to build a custom GeometryReader for learning purpose! Frankly I think every single view that we use in body is kind of GeometryReaderView with this difference that they do…
ios coder
  • 1
  • 4
  • 31
  • 91
3
votes
2 answers

SwiftUI - Drawing (curved) paths between views

In very basic terms, in my Android app, I have a screen that draws circles and then connects them with curved lines. I am trying to recreate this in SwiftUI. I found this question that seems very similar to what I am looking for, but unfortunately…
Big_Chair
  • 2,781
  • 3
  • 31
  • 58
3
votes
1 answer

SwiftUI: how to use .overlay with GeometryReader in this instance?

I know that it's common to use .background or .overlay to wrap a GeometryReader so that it doesn't modify parent views, but in this instance I don't have any views in the VStack to attach .background or .overlay to. I tried using an EmptyView then…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
3
votes
1 answer

How to cut an image into 2 using SwiftUI

I have an image like this I'd like to split it into 2 pieces across the center using SwiftUI. Leaving me with 2 separate images that I can access. However I can't figure out how to split the original into a top and bottom piece. The two pieces must…
telaCode
  • 159
  • 11
3
votes
0 answers

How to show a different layout in 2/3 Split View on iPad (SwiftUI)

I can't understand how to solve this problem... I want to show a different layout only when my app is opened in 2/3 Split View on iPad...here's some images to let you understand better... This is the correct layout when the app is in full…
3
votes
1 answer

SwiftUI: height and spacing of Views in GeometryReader within a ScrollView

ScrollView { VStack() { ForEach(0 ..< 5) { item in Text("Hello There") .font(.largeTitle) } } } The above code results in this: When we add a GeometryReader, the views lose their sizing and…
RanLearns
  • 4,086
  • 5
  • 44
  • 81
3
votes
1 answer

Using geometry reader to Center the Rectangle

I'm trying to use GeometryReader to make a Card View (to use in a card game). This Card is going to have 3 Shapes on it. I'm trying to center these 3 Shapes using GeometryReader (starting with the first shape, Rectangle), but it doesn't work. What…
user14119170
  • 1,191
  • 3
  • 8
  • 21
3
votes
2 answers

Observe frame changes in SwiftUI

I have view that can be dragged and dropped on top of other views (lets say categories). To detect which category view I'm on top of, I store their frames in a frames array, which happens in onAppear of their invisible overlays. (This is based on…
hoshy
  • 481
  • 6
  • 15
3
votes
2 answers

SwiftUI ScrollView won't center content with GeometryReader

I have a horizontal ScrollView in SwiftUI that I would like to 'dynamically' center. the content within the scrollview will be a dynamic chart, and the user can change the width of it by changing years (5, 10, 15 year chart grows…
steverngallo
  • 121
  • 1
  • 10
3
votes
1 answer

"Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols"

EDIT: Explanation to the problem This code is producing an error where the poster doesn't know how to solve it. This is a new edit of the previous post. I received the error on >Geometry Reader. This post includes all of the code. This new post…
Sydney
  • 43
  • 1
  • 5
3
votes
2 answers

SwiftUI erroneous vertical alignment of overlay when using GeometryReader

I have an overlay view that I want to appear hugging the top edge of its parent view (aligned vertically to top not center, see snapshot B) and have the ability to semi-hide it when tapped (move it up so that it doesn't obscure its parent view, and…
andrewz
  • 4,729
  • 5
  • 49
  • 67
3
votes
1 answer

GeometryReader Takes Extra Space in SwiftUI

The code below is to create a custom button import SwiftUI let skyBlue = Color(red: 75/255, green: 170/255, blue: 193/255) struct RegisterButtonView: View { var body: some View { GeometryReader { geo in HStack { …
Lance Chan
  • 31
  • 1
  • 2
1 2
3
12 13