How to scale the viewC correctly in size and position as it follow the viewB ?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Create UIViewA
let viewA = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
viewA.backgroundColor = .red
self.view.addSubview(viewA)
// Create UIViewB
let viewB = UIView(frame: CGRect(x: 150, y: 150, width: 200, height: 200))
viewB.backgroundColor = .green
viewA.addSubview(viewB)
// Create UIViewC
let viewC = UIView(frame: CGRect(x: -50, y: viewB.bounds.midY, width: 200, height: 50))
viewC.backgroundColor = .blue
viewB.addSubview(viewC)
let originalOrigin = viewB.frame.origin
// Scaling
viewB.bounds.size = .init(width: 400, height: 400)
viewB.frame.origin = originalOrigin
// How to scale viewC size and position correctly ?
}
}
I am expecting the the viewC to be like scaling correctly.
New contributor
WCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.