When I use init(check the sourcecode: from Line 10), bellow error is coming.
Return from initializer without initializing all stored properties
If I use UITableView.appearance().backgroundColor = .clear
in didFinishLaunchingWithOptions
it works fine. but that should be the case know. i need to change the color of list in one contoller alone.
Here is my code:
import UIKit
import SwiftUI
struct PortalSetupView: View {
@State var title = ""
@Binding var isNavigationBarHidden: Bool
@State var name: String = ""
let datasource: [String] = ["Hi", "Hello"]
init() {
UITableView.appearance().backgroundColor = .clear // tableview background
UITableViewCell.appearance().backgroundColor = .clear // cell background
}
var body: some View {
VStack(alignment:.leading){
Text("Hey")
.font(.system(size: 17))
.padding(.init(top: 10, leading: 0, bottom: 30, trailing: 0))
TextField("Hey there", text: $name)
Divider().padding(.init(top: 0, leading: 0, bottom: 20, trailing: 0))
List{
Section(header: Text("My header").font(.system(size: 15))) {
ForEach(datasource, id: \.self) { item in
RegionView(region: item)
}
}
}.background(Color.yellow)
.listStyle(GroupedListStyle())
Button(action: {
}){
Text("My Button").foregroundColor(.white)
.frame(minWidth: 0, maxWidth: .infinity)
}.padding()
.background(Color("LightRed"))
.cornerRadius(10)
}
.navigationBarTitle("My Navigation")
.navigationBarBackButtonHidden(true)
.onAppear {
self.isNavigationBarHidden = false
}.padding([.leading, .trailing], 18)
}
}
struct RegionView: View {
var region: String
var body: some View {
Text(region)
}
}