Post

Replies

Boosts

Views

Activity

Fetch Width and Height From UIView
How to fetch width and height of a UIView that is programatically added? Code: let View1: UIView = { let viewView = UIView() viewView.translatesAutoresizingMaskIntoConstraints = false viewView.contentMode = .scaleAspectFit print(UserDefaults.standard.bool(forKey: "backgroundColourSelected")) if UserDefaults.standard.bool(forKey: "backgroundColourSelected") { viewView.backgroundColor = self.viewColor }else { viewView.backgroundColor = .white } viewView.clipsToBounds = true return viewView }() self.canvasView.addSubview(View1) View1.centerXAnchor.constraint(equalTo: canvasView.centerXAnchor, constant: 0).isActive = true View1.centerYAnchor.constraint(equalTo: canvasView.centerYAnchor, constant: 0).isActive = true View1.widthAnchor.constraint(equalTo: canvasView.widthAnchor, constant: 0).isActive = true View1.heightAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: aspectRatio).isActive = true I want to get the final width and height by adding the above code programatically. Please help.
2
0
2.5k
Aug ’21