Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drawing square at the center of the view
@IBOutlet var animationView: UIView!
var squareView:UIView!
override func viewDidLoad() {
super.viewDidLoad()
drawSquare()
}
func drawSquare(){
let squareSize = CGSize(width: 30.0, height: 30.0)
let centerPoint = CGPoint(x: self.animationView.bounds.midX - (squareSize.width/2), y: self.animationView.bounds.midY - (squareSize.height/2))
let frame = CGRect(origin: centerPoint, size: squareSize)
squareView = UIView(frame: frame)
squareView.backgroundColor = UIColor.orangeColor()
animationView.addSubview(squareView)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment