SwiftUI - make Picker default value a placeholder - ios

Is it possible to set a placeholder text for a Swift Picker? I've been trying to search for a helpful answer but I haven't been successful so far, so hopefully this will help in solving the issue :)
Currently when passing available list values to the Picker I also pass it a default value to start of with. However, this default value is treated the same as if the user picked it. What I'm trying to achieve is that the default value should be grayed out (like regular placeholders for standard textfields) and when the user opens the picker that value would 'dissapear' as default forcing the user to pick something from the list (but without losing the range) - so f.ex. if I have a picker for values between 1-200 and I set my placeholder to 100 the picker would Still show this value when you open it (to avoid scrolling from the beginning) but it wouldn't be directly taken as the target value unless the user actually selects it.

A Menu may be a better option than a Picker in this instance.
Menu("Label") {
Button("Menu Item", action: menuAction)
Button("Other Menu Item", action: otherMenuAction)
}
Menu Documentation

Related

How to make IOS picker view to select a specific value by default

I'm getting an issue on a picker view. When the picker is opened I would like the focus to be on the active value that is 70 instead of 42. I have used generic attribute like selected for this purpose but no luck.
Screenshot
Any idea how to solve this please?
Thanks
you can set the default selected value by the following method. (in below code, 1 is the index of the row you want to select)
picker.selectRow(1, inComponent:0, animated:true)

iOS 14 UIDatePicker - allow user to clear value

Within our iOS app, we would like to give the user the option to use the UIDatePicker control but ALSO be able to clear the value after selecting it (the field allows a date OR a blank as the date is optional)
Other than change the field to be a UITextField to be able to add the clear button, is there a native way to add a clear option to the UIDatePicker? I have visions of a dustbin/trashcan on the control

VoiceOver : is 'accessibilityActivationPoint' really useful?

I tried and understood what could be the purpose of the accessibilityActivationPoint but in vain.
When a focused accessible element is activated, that property should indicate VoiceOver the specific area it's going to activate when a user double-taps the element (Apple reference) : for me, it's always the selected element itself.
I understood the selected element is considered as a block by VoiceOver, whatever the other elements inside. Once a double tap occurs to activate this block, VoiceOver calls accessibilityActivate to know what to perform (Apple reference).
1/. I've written many tests by creating a custom view including a switch control. Whatever the value of accessibilityActivationPoint inside (or outside on another switch control), the value of the switch control never changes. Is it a proper use case or am I totally wrong ?
2/. When we gather many elements inside one accessible element, how is VoiceOver able to activate one of them while they aren't accessible by definition ? Pointing one of them thanks to the accessibilityActivationPoint should work ?
Personally, I couldn't make it work and think that I'm really confusing accessibilityActivationPoint and accessibilityActivate.
Any help would be appreciated, thanks in advance.
Yes, you have the right idea with accessibilityActivate and accessibilityActivationPoint. Note that, in order for it to work, the accessibilityActivationPoint needs to be a point within the Control that you are trying to activate in on-screen coordinates (use the convert function!).
I think the short answer is "yes" to answer your second question, but, just to clear up confusion about when Accessibility Activation Point is useful, I'll go into more detail about it.
By default (aka, the default behavior for AcessibilityActivate()), when any view is activated by VoiceOver, VoiceOver will send a "tap gesture" to the center of the view. The position of this "tap gesture" can be changed by updating the accessibilityActivationPoint attribute on a view. Below, I have an example for how this property can be used.
Let's say you have a blank button (in the image below, the button is the gray box) next to some text:
For the purpose of accessibility, you may want to make the entire view that holds the button and text an Accessibility Element (so that VoiceOver users can easily understand that the button is associated with the text "Worldspace Attest"). In the image below, I am using Accessibility Inspector to show that the view holding both of these elements is an Accessibility Element.
Notice in these images that the button is not in the center of the view, but rather, it is to the right. When you activate this view using VoiceOver, the view will not select the button; instead, it will send a "tap" to the center of the view (which is the same as tapping the text, which does not do anything). In order to select the button, you have to set the view's accessibilityActivationPoint to be the on-screen coordinates of the button:
view.accessibilityActivationPoint = self.convert(button.center, to: UIApplication.shared.windows.first)
This should make it so that this button is usable by a VoiceOver user.
I hope this information clears up any confusion about the Accessibility Activation Point property. The example I used above can be found in this repository in the "Active Control Name" demo.

Add a text field on button click, that can also be saved into core data

Okay so I've been stuck on this for quite a while, and that may be because I'm pretty new to Swift and iOS in general. But what I'm trying to do is make it so when I click a button another text field will come up, and the user will be able to type stuff into it, then save that data into Core Data.
For example, I have a Dog Names application, and I have one text field already there for the user to type there Dog's name into, but then there is a button that says "Add another name?" and when they click that, a text field shows up, and can be saved into Core Data.
I'm not asking for the code for this or what not, just a direction or link or answer of how I can go about this. This feature is very important for my application, and I would really appreciate any help, thank you very much.
You could have an activeTextField variable that tracks which is the current 'name' field being used. You would be able to set this in the text field delegate textFieldDidBeginEditing method by stating activeTextField = textField
Then whatever button you are using to invoke some 'save' method, read the activeTextField.text property and save that as a new 'dog' entity or 'name' property or however you might have it set up.
You would likely want to set the activeTextField to nil in textFieldDidEndEditing

Swift ios8: How to make single row picker with option for manual text entry?

I would like to give my iPhone App user the option of whether to use a picker (i.e., scroll wheel) or keyboard to input the value of a field. I'd like it to where the current value of the field effectively displays as isolated text (i.e., as a label, with the picker and keyboard hidden). But the user can change the field's value by either (A) performing a single tap on the label to reveal the keyboard so the user can type in a different value; or (B) perform a swipe on the label to reveal the picker so the user can user the picker to change the value. This will present a very clean interface in my opinion, without the clutter of the keyboard, text field, or picker unless the user changes the value. Help?
This control doesn't exist, but a possible solution would be to add a cell under the UIPickerView (assuming your using a table form) when the "Custom" option is selected and add a text field to that cell allowing custom input. Make sure you hide the cell if the UIPickerView value changes from "Custom" to avoid user confusion.

Resources