I am manually creating the greenView
in the viewDidload()
method below and add it to miidLeView
but its coordinates in the resulting screen is wrong? What is the reason for this? Where should add it to middleView
? Thanks.
class ViewController: UIViewController {
@IBOutlet weak var redView: UIView!
var greenRegion : UIView!
let greenRegionHeight : CGFloat = 100.0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
greenRegion = UIView(frame: CGRect(x: redView.bounds.size.width*1/8,
y: redView.bounds.size.height/2 - greenRegionHeight/2,
width: redView.bounds.size.width*3/4,
height: greenRegionHeight))
greenRegion.backgroundColor = UIColor.green
redView.addSubview(greenRegion)
}