Questions tagged [viewmodifier]
59 questions
1
vote
1 answer
SwiftUI .position modifier with coordinates
I want to place items on an image with the modifier .position using the coordinates of each item. But when I look at the rendering, I don't understand the logic of the position of the items , what formula is used to place the items on the image and…

MxM
- 199
- 1
- 3
- 12
1
vote
2 answers
How to return a view with ViewModifiers
I want to return a View depending on content of an field in a array. This works, but i got a problem if i try to add ViewModifiers to the View. This won't works.
struct CodesView: View {
var body: some View {
ScrollView{
…

Enrico
- 148
- 11
1
vote
3 answers
How do I present a SwiftUI context menu conditionally?
Consider the following view code:
Text("Something")
.contextMenu {
// Some menu options
}
This works fine. What I would like to do: present the contextMenu through a view modifier indirection. Something like…

Jaanus
- 17,688
- 15
- 65
- 110
1
vote
1 answer
SwiftUI ViewModifier - add kerning
Is there a way to build a view modifier that applies custom font and fontSize, as the below working example, and have in the same modifier the possibility to add kerning as well?
struct labelTextModifier: ViewModifier {
var fontSize: CGFloat
…

Dan
- 151
- 3
- 12
0
votes
1 answer
Modifier in @Compose functions in Android Studio Kotlin Programming Language
What is difference between modifier (small m) and Modifier (capital M) when it is used in the @Compose Functions in Android Studio?
I am receiving the following output
enter image description here
by using the following code
`@Composable
fun…

Mike Foxy
- 1
- 1
0
votes
0 answers
Scrolling of the List in a view not applied to the list in its ViewModifier
I'm trying to implement an app where one of the views is a list with many elements. Thus it must be able to scroll. On the toolbar I have a switch to conditionally apply a ViewModifier that displays the same list and a Rectangle() in an HStack.
My…

Y4nn
- 1
- 1
0
votes
0 answers
How is View in swiftUI drawn in the UI when it has multiple view modifiers?
var body: some View {
ZStack {
//MARK: -3. DEPTH
Color.customGreenDark
.cornerRadius(40)
.offset(y: 12)
//MARK: -2. LIGHT
Color.customGreenLight
.cornerRadius(40)
.offset(y: 3)
.opacity(0.85)
…
user4847956
0
votes
1 answer
SwiftUI : Receive Published values with conditions
I have an Observable Object GlobalOO with a @Published value
In any View , I can observe changes with
.onReceive(globalOO.$value){ newValue in ...}
Now I only want to receive those changes according to a condition in the view
@State private var…

Gyh
- 3
- 1
0
votes
1 answer
Access the underlying UIKit view from a SwiftUI View Modifier
Is there a way to work with UIKit within the context of a SwiftUI ViewModifier?
I would like to drop to UIKit here:
struct MyViewModifier: ViewModifier {
func body(content: Content) -> some View {
// Work on `content` using UIKit here.
…

Lou Zell
- 5,255
- 3
- 28
- 23
0
votes
0 answers
Conundrum; Overlay disables button tapping. Setting .allowsHitTesting(false) disables underlying gestures
I have a nasty problem:
I use a custom ViewModifier to be able to zoom (pinch) and pan an Image. On that Image I place pins on positions relative to that image. Those pins are buttons and need to be tap-able. However, the ViewModifier puts an…

DeveloperSammy
- 167
- 1
- 11
0
votes
1 answer
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 pinch-and-zoom gesture is added to the view.…

DeveloperSammy
- 167
- 1
- 11
0
votes
0 answers
Change offset from UIViewRepresentable
I want to implement my own Offset-Modifier in SwiftUI using the current SwiftUI-View as a parameter and passing this own to a UIViewRepresentable-Wrapper to modify the frame of the SwiftUI-View in this wrapper.
I'm able to change e.g. the background…

Frank Marx
- 151
- 11
0
votes
0 answers
Automatic pop when @Environment in base view changes
In the ContentView we have a modifier set to the NavigationView which checks whether the screen is .compact or .regular. When we push the NavigationLink we go to the next screen. If we start multitasking on iPad (open 2 apps simultaneously) and…

Boyan Pavlov
- 61
- 6
0
votes
1 answer
Is it possible to add function prompt in custom tool bar viewModifier
I have created following custom toolbar modifier which I use in number of app screens . The only change on each screen is the function which added to the button! How can I add a function prompt inside the custom toolbar modifier so I can update…

mzkn
- 39
- 6
0
votes
1 answer
How do I create a View Modifier that returns a view as well as an action?
I have created a View modifier alongside a sheet manager to deal with and create popup views throughout my project. It works perfectly with a simply popup and a close button to dismiss the view. Now what I am trying to is add more functionality to…

kenada97
- 19
- 3