Change the color of a focused element (Picker) SwiftUI - WatchOS - swift

How can I change the focus color of a selected element in WatchOS7 with swiftUI. Here's my example below with a Picker whose focus color is green (the default one) but I want to change it to blue to be consistant with my app layout.
I search over the internet and stackoverflow but did not find andy solution to this. Is it possible to do it in SwiftUI.

That's the focus color and you cannot change it. At least no with standard view modifiers like .accentColor, .tint, etc.
You can try to hide it by overlying another view (like in this response), for example, or try to reach to UIKit using instrospection.
Probably it's best to be at peace with the fact that it's system behavior.

Maybe you should try using .accentColor modifier to the picker.

Related

Modify style elements of '.searchable' generated searchbar

I have a view with the .searchable() modifier. I want to change how the searchbar looks, such as the font and shape and background color.
It doesn't seem like there's any direct ways to go about this from what I've googled. I expected there to be just modifiers for it, but it seems that isn't the case.

How to modify new Date Picker in SwiftUI?

In the last update of SwiftUI, there we have got a couple of new DatePicker styles. I was trying to modify the default appearance of DatePicker. However could not find a way to do so.
This is the default view right now. I would like to resize the button and also would like to change the background colour (like making it completely transparent).
Could any one please suggest a proper way to do these modification?

How to quickly implement the color change of Appkit?

I am realizing the theme of my own application. I hope I can be quickly reacted to by other controls after I modify the color through code.
It's like this.
But I found that I couldn't change the original system color of NSColor, and I didn't want to change every child control once.
How can I achieve it?

How to make select button like Apple Pages app

I can select multiple font styles in Apple Pages app, orange colored box on the screen.
How to make it?
I can't find any ui component in the iOS SDK like this, multiple select. UISegmentControl is only for one select like radio button.
use a UISegmentControl in momentary mode to have the bar :)
set custom background images for the cells
there is no stock control but this is quite basic using this approach
No default thing is available you have to do it by yourself. You set tags for each button and only one selector. By checking the selected button tags execute you specific code.
For that, yon need to take UISegment Control and make it's background images custom. Also you can set the width of the each segment.
Then you will achieve your goal.
Cheers!

Accessibility Focus

Working with Accessibility
While VoiceOver reads the elements in the application in an order,Is there anyway to shift the focus between the elements?
I tried working with "nextResponder",but it is not working.
As of iOS 6, you can set the focus to a specific element with a UIAccessibilityLayoutChangedNotification, passing the element
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, firstBottom);
but if you're trying to completely change the “tab order” I don’t know of a way to do it.
This is a shot in the dark, but have you tried changing the accessibilityLabel or accessibilityHint in accordance when you want the order to change? If you can trick the VoiceOver to believe the text has changed, I would expect that it would change focus to it appropriately.
The timing would be the hard part, since it doesn't appear there are any delegate callbacks for when VoiceOver is crawling your view, so you may have to estimate the time to pass before trying to update the accessibility hint/value.
My last thought would be to mark the UIView that you want to bring attention to with the UIAccessibilityTraitUpdatesFrequently accessibility trait. That might be the closest you can get without tapping into hidden Apple libraries.
Check out this post for how to handle special ordering of elements for voice over. I just used this approach in the app I'm working on.
I tried UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, elementName); to change the focus on a different element. The behavior was that the focus got shifted to new element, but Voice Over would first announce the page title and then the accessible label value of the new element.
Customise Accessibility for a View:
You can customise the order(in which voice over should traverse the screen elements) by overriding accessibilityElements property of parent view in below manner.
self.accessibilityElements = [childView1, childView2, childView3]
With that voice over will follow the sequence like childView1 -> childView2 -> childView3.
Changing Accessibility focus to other element programatically:
At any time you can shift the focus to another element by using below code.
UIAccessibility.post(notification: .layoutChanged, argument: childView2)
With above code, voice over focus would be shifted to childView2 and then will follow the same sequence defined by accessibilityElements i.e. childView2 -> childView3 -> childView1... and so on
Customising Accessibility Order for Complex Views:
You can customise it further and If a view has multiple child views with further grand children views, then you can achieve accessibility order by defining accessibilityElements of main parent view by using accessibilityElements of all child views.
For example, for below view hierarchy, we have
View Controller Example
To define custom order of accessibility elements for such views, we can define in below manner.
var customElements = childView1.accessibilityElements
customElements.append(contentsOf: childView2.accessibilityElements)
customElements.append(contentsOf: childView3.accessibilityElements)
parentView.accessibilityElements = customElements