-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIView+Extensions.swift
42 lines (32 loc) · 1.09 KB
/
UIView+Extensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// UIView+Extensions.swift
// Swift Utilities
//
// Created by Tre`Von McKay on 11/8/16.
//
import Foundation
import UIKit
import QuartzCore
extension UIView{
func setCornerRadius(_ radius:CGFloat) {
self.layer.masksToBounds = true
self.layer.cornerRadius = radius
}
func setRounded(_ rounded:Bool) {
let originalFrame = self.frame
let originalWidth = originalFrame.size.width
let originalHeight = originalFrame.size.height
let origin = originalFrame.origin
var newSize:CGSize = CGSize(width: originalWidth, height: originalHeight)
if originalWidth > originalHeight {
newSize = CGSize(width: originalHeight, height: originalHeight)
}
else if originalHeight > originalWidth{
newSize = CGSize(width: originalWidth, height: originalWidth)
}
let newFrame = CGRect(origin: origin, size: newSize)
self.frame = newFrame
let radius = newFrame.size.height / 2.0
self.setCornerRadius(radius)
}
}