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`
     }
 }

}

Ganesh Amrule
  • 407
  • 2
  • 12
  • how do your custom components' definitions look? can you add those to the question as well? – holex Mar 17 '21 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. – Ganesh Amrule Mar 23 '21 at 12:57

1 Answers1

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) {
    
}
}
lorem ipsum
  • 21,175
  • 5
  • 24
  • 48