128 questions
87
votes
28
answers
109k
views
How to create TextField that only accepts numbers
I'm new to SwiftUI and iOS, and I'm trying to create an input field that will only accept numbers.
TextField("Total number of people", text: $numOfPeople)
The TextField currently allows alphabetic ...
22
votes
8
answers
27k
views
SwiftUI: Padding inside TextField
I have a TextField in SwiftUI. When I apply padding to it as
TextField(text, text: $value)
.padding()
the padding is outside of the tap area of the TextField, i.e. tapping on the padding does not ...
14
votes
4
answers
20k
views
SwiftUI email validation
How is email validation done with swiftUI?
TextField("Please enter your e-mail", text: self.$email)
.modifier(ClearButton(text: $email))
.font(.headline)
.padding(10)
....
10
votes
2
answers
1k
views
SwiftUI Form Picker only shows once
I am playing around with SwiftUI, and am currently building a Form using a Picker.
import SwiftUI
struct ContentView: View {
private let names = ["Bill", "Peter", "Johan", "Kevin"]
@State ...
9
votes
1
answer
7k
views
SwiftUI how to pass data to previous screen on dismiss
I want pass data on dismissing of presentViewController to previous screen. Here I would like to use block to pass data to previous screen as UIKitApp. But I'm not getting idea to pass data. What are ...
9
votes
0
answers
403
views
SwiftUI, iOS 14, Keyboard Avoidance in Form{ TextEditor() }
I am having a problem on a simple Form{}. Automatic Keyboard Avoidance is not working. Below is a small form with a TextEditor(). When run, the keyboard sits on top the input field, requiring the user ...
8
votes
2
answers
5k
views
SwiftUI - cells (inside Form) with clickable buttons
Goals:
Create a row/cell with buttons
Embed row/cell in a Form
What I did:
I created a cell, with buttons.
struct PointTypeButtons : View {
var body: some View {
VStack {
...
8
votes
3
answers
3k
views
How to use material design text fields in SwiftUI
I want to use the Material Design text field component in SwiftUI. There is a Material Design Text Field Component written for UIKit but not one for SwiftUI. Is it possible to use this Material Design ...
7
votes
2
answers
4k
views
Swiftui: align selected text in picker to leading edge
Currently I've a picker included in a Section included in a Form what I'm trying to reach is to align the selected value of the picker to the leading in both iOS 13 and 14, I've tried many solutions ...
6
votes
5
answers
7k
views
Spacer not working with Form inside a VStack
I'm trying to get a circle on top with the form content down below, right above my TabBar. I can somewhat force this by using .frame() but I'm not a big fan of that. It seems like there should be a ...
6
votes
2
answers
10k
views
Disable Scrolling in SwiftUI List/Form
Lately, I have been working on creating a complex view that allows me to use a Picker below a Form. In every case, the Form will only have two options, thus not enough data to scroll downwards for ...
6
votes
3
answers
3k
views
Fix odd DatePicker animation behaviour in SwiftUI form
I'm getting some odd animation behaviour with DatePickers in a SwiftUI form. A picture is worth a thousand words, so I'm sure a video is worth a million words: https://i.sstatic.net/bNrTK.jpg
I'm ...
6
votes
1
answer
8k
views
Swiftui Binding<String> action tried to update multiple times per frame
I am having trouble debugging an issue with input from textfields.
Information:
-MacOs Monterey Version 12.0 Beta 21A5284e
-Xcode 13.0 beta 3 13A5192j
-Physical phone IOS 15.0 19A297e
Issue ...
6
votes
2
answers
3k
views
Form in SwiftUI, position the user picture like in the setting of IOS using swiftUI
How can I put the image in the Form of swiftUI in order to have the same effect like the picture attached?
I have try with this code, but not working:
struct UserDetails: View {
@ObservedObject ...
6
votes
1
answer
960
views
Not possible to control animations in a Form?
Is it not meant to be possible to control the animations that take place inside of a Form view? I have here a playground that demonstrates the issue, along with a gif of what happens. As you can see, ...
6
votes
2
answers
2k
views
SwiftUI DatePicker in Form Dismisses When Keyboard Appears
I have a SwiftUI Form with a Section that contains a DatePicker. The DatePicker is set to have a datePickerStyle of CompactDatePickerStyle(), by default, since it's in a Form.
When tapping on the ...
6
votes
1
answer
6k
views
Reduce Form spacing between sections SwiftUI
I'm trying to make a notes app with SwiftUI and I'd like to show the notes similar to the Apollo Reddit app does.
The way it shows the post isn't anything special, it just shows the posts using an ...
6
votes
0
answers
553
views
SwiftUI toolbar covered by keyboard accessory view
Hi there I have a tricky problem to solve with SwiftUI in Xcode 12.4 (iOS 14): given I have a Form with numerous sections and TextEditors, this form having a .toolbar modifier (bottom bar) with some ...
6
votes
1
answer
654
views
SwiftUI Glitches in FormView
I am facing some weird glitches in my Form implementation. I am not sure whether this is some implementation error or a bug in SwiftUI itself.
So basically what I want to do is the typical "ToDo/...
5
votes
4
answers
3k
views
Deselecting item from a picker SwiftUI
I use a form with a picker, and everything works fine (I am able to select an element from the picker), but I cannot deselect it. Does there exist a way to deselect an item from the picker?
Thank you!
...
5
votes
1
answer
3k
views
SwiftUI 2.0 how to change the background color of a form section [duplicate]
I am trying to changing the black area of a section inside of a form using SwiftUI.
Since Swift 2.0 in iOS 14, a form shows these with a of padding, but using background and foreground for the colors, ...
5
votes
2
answers
2k
views
How to remove right left padding of `Form` in SwiftUI?
How to remove the left and right Padding of a Form in SwiftUI? Every View I create has padding in the leading and trailing.
Here is my code
init() {
UITableView.appearance()....
5
votes
2
answers
1k
views
SwiftUI Form with Multiple EditButtons
Trying to have a Form with multiple sections and each Section with it's own EditButton.
How to trigger a Section into "edit mode" without triggering all sections in the Form, as seen in the ...
4
votes
1
answer
3k
views
Why does the SwiftUI "Form" cause my button to go to the bottom of the screen?
I want to create a view that has a form with a button below it. If I include a form and a button, the button goes to the bottom of the screen.
Without Form Element
With Form Element
Is this just a ...
4
votes
1
answer
1k
views
How to change the background color of a form?
I'm not able to change the background color of a Form in SwiftUI for iOS < 16. It always takes default form backgroundcolor depending on which color scheme is selected in the iPhone settings. All ...
4
votes
0
answers
870
views
Strange picker view hide animation in SwiftUI form
I am trying to show and hide a picker view with an animation. The code for this is pretty simple and although the code works for other views, I can't get it to work with a picker view. Hiding the ...
3
votes
1
answer
6k
views
swiftui forms not appearing inside list
I am developing a certain application where it requires a user to fill a form. a form is not a problem actually but problem is when i want more than just one form dynamically. The number of forms (of ...
3
votes
1
answer
3k
views
How to scroll a Form to a specific UI element in SwiftUI
I have a form on a SwiftUI NavigationView.
The form has no special elements, only the standard ones: TextField, DatePicker, and some Buttons
I would like to scroll programmatically to a specific ...
3
votes
2
answers
333
views
SwiftUI sheets bolded
When I present a sheet with SwiftUI, everything gets bolded. If I swipe a bit, the bold goes away.
Example:
.navigationBarItems(leading:
Button(action:{
self.isSheetPresented.toggle()
}) ...
3
votes
1
answer
1k
views
SwiftUI: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view
How can I fix the reason why the warning appears?
struct ContentView: View {
@State private var selectedDate: Date = Date()
var body: some View {
Form {
DatePicker("...
3
votes
2
answers
4k
views
No tap animation when clicking a Button inside a Form in SwiftUI
I am using a Form in SwiftUI based on a tutorial from YouTube, and I have placed some components inside it. However, when I tap the button, it doesn't show the tap animation (For example, when I tap a ...
3
votes
1
answer
68
views
Give Form Section a Background Color/Gradient
This is my code:
Form {
Section {} // regular section no background
Section { // <--- want this section to have a background color
Text("Hello")
}
.background(Gradient(...
3
votes
2
answers
1k
views
SwiftUI Binding to a list element only updates values input in the right order
I have an edit view that is presented by a NavigationLink. It takes a recipe, which is held in a manager that has an array of them.
App Code (copy pasta should run):
import SwiftUI
@main
struct ...
3
votes
2
answers
1k
views
How do I reuse a UIViewRepresentable UIKit component?
Due to the limitations of SwiftUI, I usually need to jump back into to UIKit and take advantage of UIKit components. This is all good, but I'm finding that I usually need to keep creating separate ...
3
votes
2
answers
5k
views
SwiftUI List/Form/ScrollView being clipped when offset
I changed the y offset of a list, and now it's being clipped.
I am trying to make it so that when you scroll, you can partially see the text underneath the Title and buttons at the top of the view. In ...
3
votes
1
answer
2k
views
SwiftUI - can I make one element in Form fill the whole screen width (without horizontal margins)?
I would like a single item inside SwiftUI Form to run from side to side, without having Form's default margins.
Unfortunately, whatever I do (like ading a wider .frame, negative horizontal padding, or ...
3
votes
0
answers
330
views
SwiftUI - Style Picker like in form
How can I style a picker to make it look like in form, but without it being nested in it?
In form picker looks like a navigation link which takes you to a separate screen where you can pick one option....
2
votes
1
answer
428
views
Is it possible to get a rounded grouped table style when using the Form view in SwiftUI?
The default styling of the Form view in SwiftUI is a plain styled table view (when running in an iOS context on iPhone or iPad).
Is it possible to get a rounded grouped style table view, similar to ...
2
votes
1
answer
732
views
Filter through large Array Swift
I'm building a trip planning app that lets the user select a city from a local json file using a Picker.
The json file has 115K items and the UI freezes if I try to filter through this many items. Any ...
2
votes
3
answers
7k
views
Lazy property in SwiftUI
Hi i need help with making lazy property.
I have this code:
lazy var dateFormat: DateFormatter =
{
let formatter = DateFormatter()
formatter.locale = NSLocale.current
formatter....
2
votes
1
answer
402
views
My segmented picker has normal Int values as tags, How is this passed to and from CoreData?
My SwiftUI segmented control picker uses plain Int ".tag(1)" etc values for its selection.
CoreData only has Int16, Int32 & Int64 options to choose from, and with any of those options it ...
2
votes
1
answer
473
views
Need Bar Chart to fit inside Section()
New to SwiftUI. I have a simple form with two Section().
In one of the section, I have put BarChartView() from SwiftUICharts() as shown below.
The Bar chart does not fit in the section, needed help ...
2
votes
1
answer
925
views
XCode 12 Beta 3 SwiftUI Space between sections on a form
How can I reduce the spacing between Sections on a form for the following view?
var body: some View {
Form {
Section {
TextField("Name", ...
2
votes
1
answer
3k
views
Swiftui view not updating list after data append to array
I have three files: AddAssignment, ViewAssignment and Task.
A button is clicked on AddAssignment.swift which successfully appends form data to an array inside of Task.swift.
However, in a file ...
2
votes
3
answers
797
views
AutoComplete search in swiftui not working
I have a TextField as search box.I want to make it autosearch i.e whenever i will enter a letter in the TextField, i should get the result without press a enter.Here is my code:
TextField("Search&...
2
votes
1
answer
971
views
What do we have as UIButton(Sender: UIButton) in swiftui? [closed]
in the UIKit I catch the button sender (which button is clicked) via code
let colorVC = UIColorPickerViewController()
colorVC.delegate = self
clickedButton = sender
present(...
2
votes
1
answer
4k
views
How to auto fill a text field in SwiftUI?
I'm making an app that uses a form in SwiftUI, and I'd like to edit the objects stored locally using said forms.
In this case, I have a cake and a cookie to be stored in memory and I have two structs, ...
2
votes
0
answers
684
views
SwiftUI DatePicker in Form shows different text randomly
I am trying to use DatePicker in my app. After I select a date, the displayed text changes randomly. it changes on random dates too.
Sometimes it shows date like "Jan 26, 2021" and sometimes ...
2
votes
0
answers
682
views
Have multiple columns in a SwiftUI Form
I am looking to have multiple columns within a SwiftUI form section. I have seen other potential fixes and using .onTapGesture, but that seem's very 'hacky' and doesn't provide the same aesthetics a ...
2
votes
0
answers
1k
views
While opening fullscreenCover or sheet in a Form or List, the object what is handed to the content of the sheet is nil for the very first call
I am having a Form where an array is shown. Each row is a button where I want to open a fullscreenCover.
The issue is, for the very first time a button is triggered and the sheet is shown, the object ...