58 questions
1
vote
1
answer
77
views
How to make SwiftUI Widget buttons fill their container height when using GeometryReader with calculated row heights?
I'm building an iOS Widget (WidgetKit) with a 2×2 button grid using GeometryReader to calculate row heights. The buttons should fill their
containers completely and have equal heights, like Apple's ...
0
votes
2
answers
114
views
In SwiftUI, what's the best way to anchor one view to the containers center, while anchoring an additional view to its edge? [closed]
I'm newish to SwiftUI and trying to understand how I can keep one view horizontally centered on the device screen, while anchoring an additional view to its trailing edge (without uncentering the ...
0
votes
1
answer
90
views
Cant change zIndex of LazyVGrid element to bring it to the front with animation
I have the following example view with no zIndex modifications. Currently, when selecting a grid item, it will animate to the center of the screen. However, this does not change zIndex and items will ...
0
votes
0
answers
46
views
How to make a rectangle rotate around its own center in a ZStack
I'm working with SwiftUI and I have a rectangle inside a ZStack that I want to rotate. However, the rotation is happening around the center of the entire ZStack, not the center of the rectangle itself....
1
vote
2
answers
513
views
SwiftUI How to Set Specific Width Ratios for Child Elements in an HStack
Simplest Way to Set Specific Width Ratios for Child Elements in an HStack in SwiftUI
Hello,
I am working with SwiftUI and wondering if there's a straightforward method to set the widths of child ...
0
votes
1
answer
328
views
How to prevent text truncation when inside a ViewThatFits and with maxWidth set?
I'm curious, has anyone run into this before? I have a situation where long Text that is inside a width-limited view is being unnecessarily truncated so that it fits vertically within the parent. Is ...
0
votes
1
answer
223
views
Cannot change frame for a UIView wrapped inside a SwiftUI View
I have a UIView wrapped around a SwiftUI View. I later change the UIView size but somehow it always get back to the original size.
I have SwiftUI View wrapping around an UIView like this. This is one ...
0
votes
1
answer
114
views
How to match the size of an HStack to its parent view in certain context?
I am trying to recreate Whatsapp's message reply functionality in SwiftUI.
Basically I have a view that represents a message and the max width of the message is 300. So when a message has an older ...
0
votes
1
answer
79
views
How to replicate UIImageView's `scaleAspectFill` for Images inside a custom Layout?
I've defined a custom layout container by having a struct conform to Layout and implementing the appropriate methods, and it works as expected.
The problem comes when trying to display Image, as they ...
8
votes
0
answers
178
views
Weird crash with FocusBrigde.hasHostingController.getter in SwiftUI
This is a bug I have been trying to identify and fix for more than 3 weeks.
This bug mostly happens in production.
The stack trace doesn't help that much, because it looks like the app is crashing due ...
0
votes
1
answer
528
views
sizeThatFits method in custom layout returns invalid size for subview with fixedSize modifier
I'm writing custom SwiftUI layout and calculate container height based on child sizes. To get height of a subview I use .sizeThatFits(.unspecified) in next method:
public func sizeThatFits(
...
0
votes
0
answers
544
views
RuleMark and Chart BarMark is glitching
I am using SwiftUI Charts framework at this moment to display the last 30 days of data. As you see in code, the x axis each line is new day. The chart and animation is working fine. But the ...
1
vote
2
answers
529
views
Scrolling Inside custom layout in SwiftUI
I would like to add vertical scrolling to my custom layout. I don't know how to do it.
I have added my code below for reference. Thanks in Advance.
struct TokenData {
let email: String
}
let ...
0
votes
1
answer
2k
views
SwiftUI How to implement a custom dropdown menu like a Picker
I have been brainstorming ideas for implementing a button dropdown view similar to what you see in a default Picker. I have been experimenting with this in general to find a way to overlay a view on ...
1
vote
1
answer
812
views
How to combine GroupBox or DisclosureGroup with a List in a SwiftUI NavigationStack
Ultimately, I am trying to replicate the layout used in Apple's Tips app:
The app appears to have a NavigationStack that contains non-list items but that fit the overall list style. When I try to ...
2
votes
3
answers
2k
views
Creating Evenly Distributed Dotted Outline for a Rounded Rectangle in SwiftUI
EDIT: The dash size of 10 in the code sample is arbitrary. The dash size is whatever looks good.
Let's say in SwiftUI, you want to have a custom list item that has a dotted outline -- to serve as a &...
2
votes
1
answer
571
views
SwiftUI custom layout does not resize text views to fit container size
I am trying to implement a FlowLayout similar to what you would have in a UICollectionView.
I followed the guide from objc.io but modified it slightly to support custom spacing.
Even prior to my ...
1
vote
1
answer
225
views
How to use ideal size for HStack and VStack layout, instead of max size
HStack and Vstack usually base their layout on the maximum size of the subviews. Here is an example:
HStack {
Color.orange
.frame(idealWidth: 200, maxWidth: .infinity)
Color.purple
...
0
votes
1
answer
140
views
How can I give a sequence of Text views in a horizontal ScrollView equally sized square backgrounds in SwiftUI?
I'm working on a layout for a push-up counter app. That is my code and the result so far:
struct ContentView: View {
let sets = [1,3,6,8,12,16,23,43,56,76,100,101,125]
var body: some View {
...
1
vote
0
answers
270
views
Is there any way to access the stroke width (or style) within a SwiftUI view?
I want to create a custom Shape and give it the same height as its stroke width.
struct HorizontalLine: Shape {
func path(in rect: CGRect) -> Path {
let verticalCenter = rect....
1
vote
2
answers
2k
views
how to use custom alignmentGuide in ZStack
I want to use alignmentGuide to align center a Text view in ZStack to implement view as bellow, blue block is align traling, Text "abc" and "123" is align center of view.
My code ...
0
votes
1
answer
353
views
How does .position modifier change layout of parent Stack in SwiftUI?
I'm curious, does anyone understand what .position(x:y:) is doing to the layout process for a containing ZStack? I've looked at Apple's documentation on "Making fine adjustments to a view’s ...
1
vote
1
answer
323
views
Why does adding a frame() to an image add padding in between the image and it's sibling?
Why does adding a frame() to an image add padding in between the image and it's sibling? E.g. why is there padding underneath the A, but not the B, in this example? Thank you!
struct ContentView: ...
1
vote
1
answer
115
views
swiftui zstack are not fully centered
My code is as bellow:
struct Clock10View: View {
let light: Bool
var body: some View {
ZStack() {
Rectangle()
.frame(width: 6, height: 6)
....
1
vote
0
answers
518
views
The layout breaks when ignoring the bottom edge of the safe area in SwiftUI
I'm currently working on an app for watchOS, but this problem is the same on iOS.
When I use ignoring the bottom edge of the safe area for a view that is slightly larger than the safe area, the layout ...
0
votes
1
answer
124
views
How to use layoutPriority on 1 component while using maxWidth / minWidth on deprioritized component
I am trying to create a UI component where we have a horizontal cell containing a title / subtitle on the leading side.
Then at the trailing end of the component, there's an optional text (actionText),...
0
votes
0
answers
81
views
Why does the list run under my tab bar when using TabView on device, but not in Simulator?
When I run this code, the list is visible behind the tab bar created by the TabView. If I comment out the Image, everything is ok.
How do I make sure the list is not visible behind the tab bar?
struct ...
1
vote
0
answers
104
views
How to remove the space from top of the list
I have a swiftui app.
I want to remove the space that is automatically created on the top of the list, but without using the .listStyle(PlainListStyle()).
var body: some View {
VStack{
...
1
vote
1
answer
5k
views
How to ignore parent view's padding SwiftUI
I have a VStack with multiple child views (the one with blue background). The VStack has horizontal padding. I want to have this padding set for each child, but sometimes I have exception where I want ...
2
votes
1
answer
2k
views
Does a LazyVStack remain "lazy" if it's inside a VStack?
Let's consider a list of 100 posts. According to Apple, if I layout them inside a LazyVStack:
the stack view doesn’t create items until it needs to render them
onscreen.
What if I embed that ...
1
vote
1
answer
41
views
Adding Fixed/Scrollable Space Between Two Icons
I am looking to create a SwiftUI layout that has one icon to the far left, two icons to the far right, and a fixed-width scrollable area for any number of icons in between:
The issue I'm running into ...
1
vote
2
answers
667
views
Multiple Layouts in SwiftUI ScrollView overlap
I've implemented a left aligned flow layout using the new iOS 16 Layout protocol, and I'm using it to add two lists of items to a ScrollView as follows:
let people = ["Albert", "Bernard&...
1
vote
1
answer
541
views
SwiftUI: Centering a subview of a VStack in the main view
I want to center a TextField, which is in a VStack, to the center of the main view / screen. I tried everything I could think of. But no matter what I do SwiftUI is centering the whole VStack and not ...
2
votes
1
answer
3k
views
How to overlay view on top of multiple other views in a VStack in SwiftUI
In SwiftUI I currently have a VStack of views, and I'd like to put an overlay over the bottom two views, like this:
VStack {
Spacer()
Group {
centerView
Spacer()
}
.overlay(...
4
votes
1
answer
2k
views
Is there any way to stop a single-line of swiftUI grid items jumping in width?
Items inside a SwiftUI LazyVGrid shrink to their minWidth (80 points in my example below) when the grid view expands enough to fit another column. This is visually expected when there are multiple ...
1
vote
0
answers
239
views
How to get the current element in the screen to programmatically scroll from buttons without getting broken by the ScrollViewReader Index
I've been working on a GridView with programmatical scroll support, I've been using ScrollViewReader to programmatically scroll to the top & bottom of the GridView, but I have a trouble, I added ...
1
vote
1
answer
478
views
How to eliminate spacing around LazyHGrid items?
I've set the spacing on the LazyHGrid and the GridItems to 0, yet there is still spacing in the vertical direction. Why is that? How do I eliminate that spacing?
struct ContentView: View {
...
1
vote
0
answers
632
views
Best way to create a table with named columns in the first row in SwiftUI
I was looking for some built in functionality in SwiftUI for building a table with named columns in iOS. There appears to be a Table Function but it only works for macOS. Would the best way be to use ...
5
votes
1
answer
3k
views
SwiftUI How to Fade an Image out from the bottom Edge
Basically what Im trying to achieve is this:
To fade an image out from the top to bottom. I tried to do it with overlays but it simply does not look good
2
votes
1
answer
2k
views
SwiftUI Segmented picker inside Navigation Bar and below navigation title
What Im trying to achieve is to have a segmented picker inside the navigation bar, but below the title of the navigation bar while still having the collapse animation.
For example instead of the ...
0
votes
0
answers
1k
views
How to prevent view from being pushed by other view expanding in SwiftUI
If you have something like this. You'll see that the bottom views rectangle 1 and rectangle 2 are aligned with one another.
HStack(spacing: 0) {
Rectangle()
.fill(...
3
votes
1
answer
290
views
How to line up bottom text for child view in VStack
I have the following code which produces the following output.
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 0) {
Rectangle()
....
4
votes
0
answers
881
views
SwiftUI: LazyVGrid not refreshing while scrolling
I have a LazyVGrid that displays search results, as I type characters in the search field, I perform CoreData fetch requests and update a @Published property.
Problem:
LazyVGrid updates results as ...
0
votes
1
answer
121
views
SwiftUI truncate content of ForEach
In the following code snippet, the red circles obviously don't fit onto the screen and therefore only the trailing part of the HStack is shown. Instead of that behavior, I want the leading text of the ...
0
votes
1
answer
73
views
Looped value is showing the same result for tap
I have imported JSON for countries:
Countries.json (sample)
[
{
display_name: "France",
timezone: "placeholder",
longitude: 13.33,
...
3
votes
2
answers
8k
views
Padding, offset, or position in SwiftUI
I’m trying to position a circle to have its center sitting on top of a rectangle like this. The diameter of the circle doesn't have to be the same width as the rectangle.
What I’m trying to ...
3
votes
0
answers
2k
views
How to remove bottom default padding from List view in SwiftUI
I'm trying to remove the bottom padding on a List view when another view is being defined after it so that the List view is sitting on top of the other one. Not overlaying. There seems to be some ...
2
votes
3
answers
2k
views
How to have 2x2 made of squares fit screen in SwiftUI
I'm trying to create a 2x2 grid through either VStacks/HStacks or LazyVGrid to have the squares on each row fit the screen. For example, the first and second squares each take up half the width of the ...
2
votes
2
answers
2k
views
SwiftUI content gets cut off on smaller iPhone screens
I'm new to SwiftUI, so I'm following a tutorial to get familiar with it. However, my app's content is getting cut off on smaller screens (both vertically and horizontally). How can I prevent this from ...
3
votes
1
answer
4k
views
Is there support for something like TimePicker (Hours, Mins, Secs) in SwiftUI?
I'm trying to achieve something like iOS Timer App time picker control:
I've investigated the DatePicker, but it doesnt have seconds view.