Skip to content

Instantly share code, notes, and snippets.

@ahmed-abdurrahman
Last active October 21, 2015 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmed-abdurrahman/16c2bc83c98fd127f51e to your computer and use it in GitHub Desktop.
Save ahmed-abdurrahman/16c2bc83c98fd127f51e to your computer and use it in GitHub Desktop.
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