I have a Text and DatePicker that are supposed to go in the same row, but the row simply does not appear on iOS 15. When I put an Image instead of Text it works just fine. Other objects that prevent the row from showing up are Button and Label.
I've tried this both in sim and physical device but see the same result. iOS 16+ shows the row as expected.
Here's the sample code:
struct TestView: View {
var body: some View {
Form {
Section {
VStack {
Text("This text prevents the row from showing up.")
DatePicker("", selection: .constant(Date()), displayedComponents: .date)
.datePickerStyle(.graphical)
}
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
Post
Replies
Boosts
Views
Activity
I want to detect when the user stopped touching the screen. But I want it to be in a vertical ScrollView and a DragGesture isn't recognized when the view is scrolled vertically. I'm guessing this is because there wasn't anything dragged, since the view moved along with the user's finger.
import SwiftUI
struct TestView: View {
var body: some View {
ScrollView {
VStack(spacing: 0) {
Rectangle()
.foregroundStyle(.green)
.frame(height: 700)
}
}
.gesture(DragGesture().onEnded({ _ in print("Drag gesture ended") }))
}
}
How should I go about detecting when the user lifted their finger off the screen on a scrollview?
Is there a way to keep the menu open after tapping on a button or toggle inside it instead of automatically minimizing it on every tap?
This isn't a feature that's going to production ever, by the way.
My code is something like this:
struct MyView: View {
@State var toggleA = true
@State var toggleB = true
@State var toggleC = true
var body: some View {
NavigationView {
SwiftUI.Form {
Text("Hello")
}
.navigationTitle("My View")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing: {
Menu {
Toggle("A", isOn: $toggleA)
Toggle("B", isOn: $toggleB)
Toggle("C", isOn: $toggleC)
} label: {
Image(systemName: "ellipsis.circle")
}
}())
}
}
}
struct Preview: PreviewProvider {
static var previews: some View {
MyView()
}
}
I want a button that will invert the values between Text1 and Text2. But my problem is: I want its center to be at the center of the rows, so essentially it would be exactly where the divider lies.
Form {
Section {
Text("Text 1")
// button goes here
Text("Text 2")
}
}
I have tried a ZStack in Text1 with an offset, but this makes half of the button hide beneath Text2. I have also tried an overlay on Text 1 but the same thing happens, while an overlay on the entire Section gives me a button for each row.
I know there are ways to create my own "Section" view, but if there is a way to avoid this I would much prefer it because I find myself dealing with a lot of custom padding to attempt to resemble a real row, but it never looks the same.
I have a widget extension that needs to use some UserDefaults written from my host app. I didn't want to use UserDefaults(suiteName:) since it's an optional, so I used the following property from [this article]:(https://www.swiftbysundell.com/articles/the-power-of-userdefaults-in-swift/)
extension UserDefaults {
static var shared: UserDefaults {
let combined = UserDefaults.standard
combined.addSuite(named: appGroupName)
return combined
}
}
But when I call it in the extension, the values are not present. Is this expected behavior?
For the record, I am 100% sure I have the right app groups. I also made a new project only to test this and it's behaving identically.
And I'm not calling .synchronize() for UserDefaults anywhere, but I don't think that's needed.
I'm implementing the iOS 16 AppIntents framework and it works fine except when I try to trigger it with Siri, which just pulls up results from the web. Here's a very simple version I made on an empty project.
import Foundation
import AppIntents
@available(iOS 16.0, *)
struct ShowMeBooks: AppIntent {
static var openAppWhenRun: Bool = false
static var title: LocalizedStringResource = "Show me my books"
func perform() async throws -> some IntentPerformResult {
let x = 1 + 1
return .finished(dialog: "Here are your books")
}
}
@available(iOS 16.0, *)
struct SouthwestShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: ShowMeBooks(),
phrases: ["Show me my books on \(.applicationName)"]
)
}
}