Questions tagged [viewmodifier]
59 questions
41
votes
4 answers
SwiftUI view with rounded corners AND border
ZStack {
VStack {
Text("some text")
Button("Ok") {}
.foregroundColor(.cyan)
.padding()
}
.padding()
…

soleil
- 12,133
- 33
- 112
- 183
10
votes
3 answers
SwiftUI ViewModifier for custom View
Is there a way to create a modifier to update a @State private var in the view being modified?
I have a custom view that returns either a Text with a "dynamic" background color OR a Circle with a "dynamic" foreground color.
struct ChildView: View {
…

Aнгел
- 1,361
- 3
- 17
- 32
9
votes
1 answer
SwiftUI: ViewModifier where content is a Shape
The following code works fine. So really, I’m good ... But I wanted to learn about ViewModifiers ... so my goal is to separate the non-changing stuff from the dynamic stuff to create a .cardify() custom modifier to call on the Shapes Views.
struct…

RichWalt
- 502
- 1
- 4
- 13
5
votes
1 answer
How to use .quickLookPreview modifier in swiftui
I am trying to use the view modifier .quickLookPreview introduced in iOS 14, macOS 11 macCatalyst 14 but I get this error Value of type 'some View' has no member 'quickLookPreview' every time I try to use the modifier on a macOS or mac catalyst…

Heyman
- 449
- 4
- 13
4
votes
1 answer
SwiftUI ViewModifier animation not showing properly everytime
I have created a ViewModifier that adds a icon to the right of a its content, the way I want the icon to appear is by animating the .clipShape() modifier from -50 to 0, the problem is that when appearing the first time, it just pops out with no…

Javier Heisecke
- 1,162
- 1
- 11
- 28
4
votes
3 answers
SwiftUI: Conditionally hide a view without recreating it
The issue with Conditional View Modifiers
I made heavy use of conditional view modifiers in SwiftUI until I had some issues with it and recently discovered it is a bad idea.
From my understanding now, doing something like this:
if condition {
…

BlackWolf
- 5,239
- 5
- 33
- 60
4
votes
2 answers
SwiftUI: custom view modifier not conforming to ViewModifier?
I am trying to create this modifier:
struct CustomTextBorder: ViewModifier {
func body(content: Content) -> some View {
return content
.font(.largeTitle)
.padding()
.overlay(
…

zumzum
- 17,984
- 26
- 111
- 172
3
votes
2 answers
TextField ViewModifier not conforming to ViewModifier?
I have this code in one of my views:
struct TextFieldClearButton: ViewModifier {
@Binding var text: String
func body(content: Content) -> some View {
HStack {
content
if !text.isEmpty {
…

zumzum
- 17,984
- 26
- 111
- 172
3
votes
0 answers
Can I support `labelsHidden` modifier in custom view/style?
I have a custom Toggle style but it doesn't work with labelsHidden() view modifier. Is it possible to support it?
I know that I can add a property to my style or hide it right in the body, but I wondering if I can support exactly this modifier

Kruperfone
- 126
- 7
3
votes
0 answers
Overlay in front of SwiftUI tab view
I'm using SwiftUI's TabView and I want to add a custom bottomSheet() modifier which accepts a view and displays it like the standard sheet() modifier, but without occupying the entire screen.
Current Behaviour: I managed to create the custom…

Siddharth Kamaria
- 2,448
- 2
- 17
- 37
3
votes
0 answers
macCatalyst app builds but won't launch on Mac
I am designing a swiftUi app which runs seamlessly on iOS 14 simulators and devices, but fails to launch on the Mac (10.15.7).
The app builds without issues, then I have this in the console:
dyld: Symbol not found:…

NightCoder
- 1,049
- 14
- 22
2
votes
0 answers
Show a view on top of a Sheet - SwiftUI
I want to show a Sheet, and then show a certain view (toast in my case) over all the NavigationView, including the Sheet, but it's showing behind the Sheet.
This is my Toast ViewModifier:
struct Toast: ViewModifier {
//MARK: - PROPERTIES
…

Elias Al Zaghrini
- 237
- 2
- 13
2
votes
1 answer
Overlaying image on scenePhase when sheet is open
I've made a ViewModifier for my app so that when it goes into .background phase it shows a splash of an image. However, when a .sheet or a .fullScreenCover is presented it doesn't seem to be triggering the modifier or detecting scenePhase…

markb
- 1,100
- 1
- 15
- 40
2
votes
1 answer
SwiftUI ViewModifier not working as a NavigationLink
I have the following ViewModifier and it does not work:
import SwiftUI
struct NavLink: ViewModifier {
let title: String
func body(content: Content) -> some View {
NavigationLink(destination: content) {
Text(title)
…

AD Progress
- 4,190
- 1
- 14
- 33
2
votes
2 answers
SwiftUI ViewModifier: How to create view modifier functions without using View extensions?
I'm building a CustomTextField View and wanting to add view modifiers.
Using the standard .modifier(CustomViewModifier) is working just fine. Now I want to build ViewModifier functions so that I can use my modifiers just like any other SwiftUI…

James Futures
- 185
- 2
- 12