HomeiOS Developmentios - Why is Swift ViewController not in a position so as...

ios – Why is Swift ViewController not in a position so as to add subviews?


I’m attempting to work with a view controller in SwiftUI. I need to add a textual content label as a subview on the view controller, however any subview I add will not be displayed on the display screen. The code is as follows:

override func viewDidLoad() {
        tremendous.viewDidLoad()
        view.backgroundColor = .blue
        self.seem()
    }
    
func seem() {
        let label = UILabel()
        label.textual content = "Whats up, World!"
        label.textAlignment = .heart
        label.font = UIFont.systemFont(ofSize: 24)
        label.textColor = UIColor.inexperienced
        label.translatesAutoresizingMaskIntoConstraints = false
        
        print("including textual content")
        DispatchQueue.important.async{ [weak self] in
            self!.view.addSubview(label)}
        view.setNeedsLayout()
        view.layoutIfNeeded()
        print ("textual content added")
    }

Solely a blue background is displayed however the textual content will not be. I even added two print statements to verify if the code block is even executed, and it’s however for some cause the textual content will not be displayed. Any assist to repair this will likely be a lot appreciated.

ps: I’m displaying this view controller as a swift view inside a VStack through the use of a UIViewControllerRepresentable wrapper for the view controller.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments