Last active
October 21, 2015 06:36
-
-
Save ahmed-abdurrahman/16c2bc83c98fd127f51e to your computer and use it in GitHub Desktop.
Drawing square at the center of the view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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