5 // Created by Pawel Dabrowski on 30/05/2018.
6 // Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
14 func addConstraintsFllingContainer(toView: UIView){
16 toView.translatesAutoresizingMaskIntoConstraints = false
17 let viewsDictionary:[String: AnyObject] = ["toView": toView]
19 addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[toView]|", options: [], metrics: nil, views: viewsDictionary))
20 addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[toView]|", options: [], metrics: nil, views: viewsDictionary))
23 func centerInSuperview() {
24 self.centerHorizontallyInSuperview()
25 self.centerVerticallyInSuperview()
28 func addConstraingWidth(width: CGFloat){
29 let c: NSLayoutConstraint = NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: width)
33 func centerHorizontallyInSuperview(){
34 let c: NSLayoutConstraint = NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: self.superview, attribute: .centerX, multiplier: 1, constant: 0)
35 self.superview?.addConstraint(c)
38 func centerVerticallyInSuperview(){
39 let c: NSLayoutConstraint = NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: self.superview, attribute: .centerY, multiplier: 1, constant: 0)
40 self.superview?.addConstraint(c)
43 func addDropShadow(height: CGFloat = 2, radius: CGFloat = 3) {
44 layer.masksToBounds = false
45 layer.shadowColor = UIColor.black.cgColor
46 layer.shadowOffset = CGSize(width: 0, height: height)
47 layer.shadowOpacity = 0.2
48 layer.shadowRadius = radius
51 func rotate(angle: Double) {
52 let radians = angle / 180.0 * Double.pi
53 let rotation = CGAffineTransform.init(rotationAngle:CGFloat(radians))// CGAffineTransformRotate(self.transform, CGFloat(radians));
54 self.transform = rotation