Frank Boccia Frank Boccia - 1 year ago 107
iOS Question

Creating multiple UIViews from button pressed Swift

I have a UIView called brokeView, It is draggable and rotational. I am trying to allow the user to populate the same exact view from clicking a button allowing an endless amount of the same UIView to populate. Is this possible to do in swift using the storyboard?
- Do I have to create all the views in storyboard or could I populate them through code using an array or loop?

@IBOutlet weak var brokeView: UIView!

@IBAction func showBrokenAnnotation(sender: AnyObject) {
brokeView.hidden = false
for i in 1...10 {
let newView = UIView(frame: brokeView.bounds)

Answer Source

This can be done through code. Here is some pseudo code.

Updated from our conversation below - this makes it the same size as your "brokenView" and then you can set the x/y however you want.

 let newView = UIView(frame: CGRect(x: 0, y: 0, width: mainView.frame.width, height: mainView.frame.height))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download