I am fairly new to swift, and I had been doing all of my coding programmatically. I finally branched out and started learning some awesome things using the Interface Builder and what not.
I have created some cool custom drawings in a UIView class I created using the drawRect(rect: CGRect) function, and now I want to be able to call that class multiple times in a loop to layout in my view. Whenever I try to instantiate the view programmatically, it seems as though drawRect is not getting called. I'm not getting any errors, just nothing is drawing. Here is my code for laying out the custom view, where TesterView is my custom UIView subclass that performs the custom drawing:
func testView() {
let testerView:TesterView = TesterView()
self.view.addSubview(testerView)
testerView.translatesAutoresizingMaskIntoConstraints = false
let height = NSLayoutConstraint(item: testerView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 200)
let width = NSLayoutConstraint(item: testerView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 200)
let centerX = NSLayoutConstraint(item: testerView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: testerView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
self.view.addConstraints([height, width, centerX, bottom])
}
Any and all help would be greatly appreciated. I didn't start trying to call the view in a loop yet because I can't even get it to work once. What I need to do eventually is loop through and instantiate the class multiple times.