[ad_1]
So, I’ve this ViewController the place I render a picture inside a subview.
class ViewController: UIViewController {
override func viewDidLoad() {
tremendous.viewDidLoad()
view.backgroundColor = .systemBackground
let childView = UIView()
childView.backgroundColor = .purple
let imageView = UIImageView(picture: UIImage(systemName: "tray"))
imageView.contentMode = .scaleAspectFill
childView.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
imageView.heightAnchor.constraint(equalToConstant: 100.0)
])
view.addSubview(childView)
childView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
childView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor)
])
}
}
As you possibly can see for some cause, the picture strikes to the left of display screen. What’s the explanation for that?
Yet one more factor I seen is the subview ought to have a background shade of purple as specified, however in some way it is clear. Why is that?
I count on the end result to be one thing like,
[ad_2]


