Questions tagged [swiftui-button]
58 questions
11
votes
2 answers
SwiftUI: Is there a way to put a button inside of a button?
I am trying to insert a button inside of another button using SwiftUI. However, if I press that button, it also animates the outer button being pressed, even though it doesn't run the action closure. Is there a way to prevent this, perhaps using a…

1-877-547-7272
- 183
- 7
4
votes
1 answer
Animation transition of one gradient to another SwiftUI
I was trying to change the gradient of a background depending on the value of a state value which should be possible, and it is. However, I wanted to animate this change of gradient/background (as you often do when a property depends on some…

Evan
- 1,892
- 2
- 19
- 40
3
votes
2 answers
Button is not Taking Given Height and Width in SwiftUI
I am new to swiftui. I am making a login screen in which I have to use log in with apple and gmail buttons. I am using a custom view to design the button. Here is the code for that custom button view:
struct CustomSocialButton: View {
var…

Taimoor Arif
- 750
- 3
- 19
3
votes
1 answer
Is there a way to set font tracking (i.e. spacing) inside a custom SwiftUI ButtonStyle?
In SwiftUI you can set font tracking (spacing between letters) on a Text View using the tracking View modifier:
Text("Hello, World!")
.tracking(10)
If you have a Button and apply your custom ButtonStyle you can do all kinds of modifications to…

shim
- 9,289
- 12
- 69
- 108
3
votes
1 answer
SwiftUI - Dynamic Edit Button on Nav Bar
I'm fairly new to Swift/SwiftUI - I'm working on a simple to-do list app and trying to make a Nav bar button that changes from the built-in Edit button to a custom button depending on a state variable.
I attempted this using a ternary operator like…

charlesj
- 33
- 2
3
votes
1 answer
SwiftUI Animation onLongPressGesture(minimumDuration: 0.5) automatically starts
I've created a circular button which I specified to show scale animation on .onLongPressGesture(minimumDuration: 0.5)
the code is bellow:
struct PlayerTouch: View {
@State private var animationAmount: CGFloat = 1
@State var animationEffect =…

Azhman Adam
- 43
- 6
2
votes
1 answer
SwiftUI - Combine buttonStyle functionality with different functions for each button
I am new to SwiftUI and iOS. What I am trying to achieve is to add a buttonStyle to all the buttons inside my app, while keeping the function that each button calls when pressed. This is my code so far for the buttonStyle. It works as expected…

GeorgeHTS
- 41
- 3
2
votes
1 answer
How do I persist the button color after favoriting in SwiftUI?
I would like my favorites button to switch colors based on if the user favorites or unfavorites a character. I am able to change the text from "Favorite" to "Favorited" and change the color initially. If I exit the app, the button color goes back to…

Kevin
- 27
- 7
2
votes
0 answers
SiwftUI nested buttons, child tap triggers parent animation
I have been looking around but couldn't find the solution so lets hope someone can help me.
I have a ScrollView with a LazyVStack in it. Then I have a list of 'cells'.
Simplified it looks something like
Button(action: { ... }) {
HStack {
…

Saren Inden
- 3,450
- 4
- 32
- 45
2
votes
1 answer
SwiftUI Multiple Buttons with Popovers in HStack Behavior
When having multiple buttons with popovers in an HStack, I get weird behavior. Whenever you tap one button, the popup shows up correctly. But, when you click on the second item, the first popover quickly closes then reopens. Expected behavior is…

MostPalone
- 77
- 7
2
votes
2 answers
SwiftUI's keyboardShortcut is not working if Button has a buttonStyle
My code:
Button(action: {
AudioServicesPlaySystemSound(1026)
isActive.toggle()
}){
HStack{
Image(systemName: "trash")
…

suriya_1403
- 37
- 6
2
votes
1 answer
While using an if statement: Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols
I am trying to implement a button that activates a ForEach loop to go through each item in the list and mark it as delayed. This is my code:
import SwiftUI
struct AllJobsDelayWeather: View{
var jobIndividualViewModel: JobIndividualViewModel
…

FrankDad
- 23
- 7
2
votes
1 answer
macOS SwiftUI Button "Active Area" Width of Parent View
For a macOS app, I like to extend a button's width across it's parent view using SwiftUI. I tried this:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Button(action: {print("TEST")}) {
…

DaPhil
- 1,509
- 4
- 25
- 47
2
votes
1 answer
SwiftUI Navigation Link containing a Button
I have a SwiftUI list that looks like this:
List {
ForEach(items) { item in
NavigationLink(destination: EditItemView(item: item)) {
ItemView(item: item, buttonAction: {
// Do something
})
}
}
where ItemView…

nikmin
- 1,803
- 3
- 28
- 46
1
vote
1 answer
Prevent that multiple buttons can be pressed simultaneously in SwiftUI
I have a SwiftUI app with a complex dashboard view consisting of several other nested custom SwiftUI views containing SwiftUI buttons.
I want to prevent that these different buttons can be pressed simultaneously with multiple fingers and execute…

mahega
- 3,231
- 4
- 20
- 32