UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Project 14 (day 73) Bucketlist Challenge 1

Forums > 100 Days of SwiftUI

Does anyone know WHY the button works better when the modifiers are on the image as opposed to the button itself?

      //This button is hard to press
      Button {
          //do stuff
      } label: {
          Image(systemName: "plus")
      }
      .padding()
      .background(.black.opacity(0.75))
      .foregroundColor(.white)
      .font(.title)
      .clipShape(Circle())
      .padding(.trailing)
      //This button is easier to press
      Button {
          //do stuff 
      } label: {
          Image(systemName: "plus")
              .padding()
              .background(.black.opacity(0.75))
              .foregroundColor(.white)
              .font(.title)
              .clipShape(Circle())
              .padding(.trailing)
      }

2      

This from the Paul Hudson

When we apply modifiers to the label inside a button, they all become part of that label – they all become the thing you click on to trigger the action. However, when we apply modifiers to the button rather than the label, we’re adding modifiers outside the label, which won’t become part of the clickable area.

Hope it helps ... good luck

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.