80 questions
0
votes
1
answer
91
views
How to make a specific subtext of Text view tappable and open a popover
I have a long label that I want to make into a Text view. For example:
"This is a really long text that is guaranteed to wrap around into 2 lines. There might be a solution. Click me to find out!&...
0
votes
1
answer
83
views
Controlling @State value from inside a function
Within a View, I'm calling a function that references some external objects and updates a chart. For the time when function is processing I would like to hide the chart and replace it with a ...
0
votes
1
answer
190
views
Translucent background for fullScreenCover custom menu
I need to make a transparent background when a menu opens. I press the button menu and I need to see a centre screen component with three menu items to choose and transparent background.
This is my ...
0
votes
1
answer
62
views
SwiftUI: Dynamic Label and Image adjust
We have vertically aligned multiple labels and top tight Image is align to first label.
If first label has not enough content then second label will be move up and vice versa.
image height will be ...
1
vote
1
answer
95
views
Don't redraw some of the view structure
Consider the following code that draws a grid of randomly colored rectangles on the screen, with a Circle that moves to right by responding to a timer:
struct ContentView: View {
let width: ...
-2
votes
1
answer
320
views
Passing data through Navigationlink with custom views - SwiftUI
Im trying to pass two kinds of different JSON data in an app with two different views in two navigationlinks, what works
One custom view which with the name LaundryList that gets passed in the ...
1
vote
1
answer
436
views
What is the explanation of observing a constant data change in SwiftUI View
When I study the SwiftUI Apprentice book of Kodeco, I come across the below code snippet.
struct CountdownView: View {
let date: Date
@Binding var timeRemaining: Int
let size: Double
var body:...
0
votes
1
answer
403
views
How do we constrain the layout of two Views to have the same position and size in SwiftUI?
I am a mildly experienced UIKit/AppKit developer, but I am just getting started using SwiftUI. In UIKit it is straight forward to constrain two UIView's to have the same size and position using ...
0
votes
0
answers
226
views
OnTapGesture ALWAYS registers out of frame or view
I'm new to Swift, trying to do a personal project and I currently am stuck at a thing for which I cannot find a resolution anywhere for the past week.
This is the code:
import SwiftUI
struct ...
0
votes
1
answer
726
views
SWIFTUI ViewModifier using UIViewRepresentable; getting a value from the UIView to my SwiftUI View
I have a custom modifier on a SwiftUI View to pan and zoom an Image. I need to get the location where the user long presses. The modifier uses an UIView (UIViewRepresentable) under the hood where the ...
6
votes
3
answers
2k
views
SwiftUI: Detect NavigationView goes back to main view
I have a NavigationView and the following view structure ViewA -> ViewB -> ViewC and I'm trying to figure out how to detect when ViewB goes back to ViewAViewB -> ViewA. Here is my Code:
...
0
votes
1
answer
136
views
SwiftUI animated background view adjust width according to size changes (orientation)
I have an animated background view which is a struct (the view) that instantiates a class. It represents stars animating and moving from right to left on the screen.
The view (StarsView) is given a ...
2
votes
1
answer
133
views
How can I return a struct which indirectly inherits the View protocol via another protocol in SwiftUI?
Suppose I have the following protocol which conforms to View:
protocol Foo: View {
init(field: Binding<Bool>)
}
I then have two structs which conform to this protocol:
struct BarView: Foo {
...
0
votes
1
answer
147
views
How to refactor almost identical conditional code in SwiftUI view
I have the following that I'm using for an input field where the user can enter an API token. By default it's presented as a SecureField, but the user can click the "eye" icon and change to ...
0
votes
1
answer
96
views
Showing a view within a VStack causes other views within VStack to resize
I have a VStack of views which serve to act as a list of expanding rows. As you tap on any row, it expands to show further details. So long as I only have one row "expanded" at a time, ...
1
vote
2
answers
385
views
I am unable to use a spacer to push a text view to the top of my swift ui VStack view, when adding UI wrappers
I have got a piece of code below but the issue is the text field is positioned in the middle of the view and when I add spacers below to push the textfield to the top of the view, it doesn't get ...
11
votes
0
answers
863
views
Why does ForEach initialize its Child View twice as much in SwiftUI?
I came across a weird behaviour of SwiftUI's ForEach view.
I've noticed that ForEach always initialize its child view twice as much as it should according to its repetition. Normally, when you render ...
2
votes
4
answers
2k
views
How to get a Navigation Title aligned with Back Button?
I'm trying to get the navigation title vertically aligned with the back button in a NavigationDetail view in SwiftUI. Here's what this looks like currently:
Below's my code for adding the Navigation ...
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(...
1
vote
2
answers
2k
views
SwiftUI - How to overlay or ZStack a View so that it doesn't affect the position of the underlying View?
I want to place an image either on top of, or between lines, depending on the position variable:
struct ContentView: View {
@State var position = 5
var body: some View {
VStack(spacing: ...
-2
votes
1
answer
447
views
SwiftUI - How to pass data from childView's viewModel to parentView's viewModel?
I have SwiftUI view1, with its viewModel1.
view1 has a child view view2 with viewModel2.
How can I pass a data for viewModel2 to viewModel1?
Thanks!
1
vote
1
answer
2k
views
SwiftUI function shows "Modifying state during view update, this will cause undefined behavior."
The code works in that it brings up 5 random consonants and 2 vowels just like I want, but it is showing a warning message that "Modifying state during view update, this will cause undefined ...
1
vote
2
answers
6k
views
How to Align an image to the center of a screen using SwiftUI?
I'm trying to align an image to the center of the screen in Swift/SwiftUI.
GeometryReader { geometry in
HStack {
Spacer()
Color.white
....
0
votes
1
answer
1k
views
How do I show another SwiftUI View with code?
Im trying to show another view with SwiftUI, when a button is pressed. Here is what I am trying:
import SwiftUI
struct Home: View {
var body: some View {
VStack {
Text(/*@...
1
vote
1
answer
2k
views
SwiftUI - view expand from the bottom of frame
I'd like to display a number of values as a continuous value from 0 to 1. I'd like them to grow from the bottom up, from 0 displaying no value, to 1 displaying a full height.
However, I'm unable to ...