2

I have a row of .bordered image buttons. And I want all of them to fill the height of the container, by setting frame(maxHeight: .infinity). However, although the buttons themselves are properly sized, the gray background depicting the border is not. See the attached image. Basically, I want the gray background to fill up to the blue borders.

Bordered buttons do not appear to be the same height

And here's the simplified code I have.

HStack {
  Button(action: { }) {
    Image(systemName: "phone.connection.fill").foregroundColor(.green)
  }
  .buttonStyle(.bordered).fixedSize()
  .frame(maxHeight: .infinity)
  .border(Color.blue)

  Button(action: {  }) {
    Image(systemName: "phone.down.fill").foregroundColor(.gray)

  }
  .disabled(true)
  .buttonStyle(.bordered).fixedSize()
  .frame(maxHeight: .infinity)
  .border(Color.blue)

  ...
  
}

Any suggestions on how to achieve this? Thanks.

1 Answer 1

1

Your View is close, but the placement of the frame and fixedSize modifiers have to be changed a bit:

struct ContentView: View {
    var body: some View {
        HStack {
          Button(action: { }) {
            Image(systemName: "phone.connection.fill")
                  .foregroundColor(.green)
          }
          .buttonStyle(.bordered)
          .border(Color.blue)

          Button(action: {  }) {
            Image(systemName: "phone.down.fill")
                  .foregroundColor(.gray)
                  .frame(maxHeight: .infinity)
          }
          .disabled(true)
          .buttonStyle(.bordered)
          .border(Color.blue)
        }
        .fixedSize(horizontal: false, vertical: true)
        .border(Color.green)
    }
}

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Aha, got it. Thanks. The image itself needs to have an infinity height to fill it its parent, the button!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.