Post

Replies

Boosts

Views

Activity

resize image from UIImage inside UIButton with swiftUI
Hello, I'm having a little issue with this code. struct nfcButton : UIViewRepresentable {     @Binding var data: String     @Binding var showData: Bool     func makeUIView(context: UIViewRepresentableContext<nfcButton>) -> UIButton {         let button = UIButton()         button.setImage(UIImage(named: "phoneFinal"), for: .normal)         button.addTarget(context.coordinator, action: #selector(context.coordinator.beginScan(_:)), for: .touchUpInside)         return button     } I just change my image with a better and bigger one. The thing is don't know how to resize it. I tried to add .frame to the structure call like so : nfcButton(data: $data, showData: $showNFCMobile) &#9;&#9;.frame(width: 150.0, height: 250.0) I also tried with resizableImage method but I don't really understand what is the capInsets button.setImage(UIImage(named: "phoneFinal")?.resizableImage(withCapInsets: <#T##UIEdgeInsets#>), for: .normal) I know in my regular view I just need to make like this and it works; Image("Image_name").resizable().frame(width: 150) Thank for your help !
1
0
2.9k
Jul ’22
resize image from UIImage inside UIButton with swiftUI
Hello, I'm having a little issue with this code. struct nfcButton : UIViewRepresentable {     @Binding var data: String     @Binding var showData: Bool     func makeUIView(context: UIViewRepresentableContext<nfcButton>) -> UIButton {         let button = UIButton()         button.setImage(UIImage(named: "phoneFinal"), for: .normal)         button.addTarget(context.coordinator, action: #selector(context.coordinator.beginScan(_:)), for: .touchUpInside)         return button     } I just change my image with a better and bigger one. The thing is don't know how to resize it. I tried to add .frame to the structure call like so : nfcButton(data: $data, showData: $showNFCMobile) &#9;&#9;.frame(width: 150.0, height: 250.0) I also tried with resizableImage method but I don't really understand what is the capInsets button.setImage(UIImage(named: "phoneFinal")?.resizableImage(withCapInsets: <#T##UIEdgeInsets#>), for: .normal) I know in my regular view I just need to make like this and it works; Image("Image_name").resizable().frame(width: 150) Thank for your help !
Replies
1
Boosts
0
Views
2.9k
Activity
Jul ’22