0

We have designed some custom controls for our app like CustomButton, CustomTexView, etc. for our application. These controls defines theme of application and have standard size. Now we are planning to use SwiftUI in our project. How to use these custom controls in SwiftUI structure?

i.e.

struct ContentView: View {
  var body: some View {
     HStack {
        Text("SwiftUI from ContentView2")
        Rectangle() //Here we need to add custom button. i.e. CustomButton defined in our project which is written in UIKit`enter code here`
     }
 }

}

2
  • how do your custom components' definitions look? can you add those to the question as well? Commented Mar 17, 2021 at 12:35
  • We have defined wrapper around some of the controls provided by Apple such as UIButton has wrapper MyButton it internally defines properties and colours e.g primary, secondary etc. Primary button has 44px height and blue color, secondary has white color etc. This helps us to maintain consistency across app. Due to company policy unable to paste exact code here. Commented Mar 23, 2021 at 12:57

1 Answer 1

1

This code belongs with this question the original poster has a lot of information with it. It isn't the answer for it but it is a good example on how to convert an existing Storyboard into a SwiftUI View

import SwiftUI

struct ContentView: View {
var body: some View {
    StoryboardViewController()
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
    ContentView()
}
}

struct StoryboardViewController: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> some UIViewController {
    let storyboard = UIStoryboard(name: "Storyboard", bundle: Bundle.main)
    let controller = storyboard.instantiateViewController(identifier: "Main")
    return controller
}

func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
    
}
}
Sign up to request clarification or add additional context in comments.

Comments

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.