Home > OS >  Apply corner radius to only two corners for button in Swiftui
Apply corner radius to only two corners for button in Swiftui

Time:08-03

Problem and Try

struct PlayGroundThirdView: View {

 //some variables
 //some vm and controller

  var body: some View {
    //some views

    Button {
        vcontroller.fetch()
        vcontroller.setColor(.red)
    } label: {
        Text("Refresh")

    }
    .frame(width: 50, height: 50, alignment: .leading)
    .foregroundColor(.white)
    .background(.red)
    .cornerRadius(20)
    
 }


}

I want corner radius of button only apply to TWO corners Only for leading direction but has never work with clipshape or even alignment leading.

What i actually want enter image description here

CodePudding user response:

Can be achieved with working with just padding() for this case.

enter image description here

HStack {
  Spacer()
  Button("Refresh") {
  ...
  }
  .padding(10)
  .foregroundColor(.white)
  .background(.red)
  .padding(.trailing, 20) //corner radius part
  .cornerRadius(20) //corner radius part
  .padding(.trailing, -20) //corner radius part
}
  • Related