-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e75c857
commit b3e59fd
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// CALayer+.swift | ||
// Rx | ||
// | ||
// Created by taehy.k on 2021/08/31. | ||
// | ||
|
||
import UIKit | ||
|
||
extension CALayer { | ||
func applyShadow(color: UIColor, | ||
alpha: Float, | ||
x: CGFloat, | ||
y: CGFloat, | ||
blur: CGFloat) { | ||
masksToBounds = false | ||
shadowColor = color.cgColor | ||
shadowOpacity = alpha | ||
shadowOffset = CGSize(width: x, height: y) | ||
shadowRadius = blur / 1.0 | ||
} | ||
|
||
/* | ||
다음과 같이 사용: view.layer.addBorder([.top, .bottom], color: UIColor.white, width: 1.0) | ||
Default: .all, .black, 1.0 | ||
*/ | ||
func addBorder(_ edges: [UIRectEdge] = [UIRectEdge.all], color: UIColor = .black, width: CGFloat = 1.0) { | ||
for edge in edges { | ||
let border = CALayer() | ||
|
||
switch edge { | ||
case UIRectEdge.top: | ||
border.frame = CGRect.init(x: 0, y: 0, width: frame.width, height: width) | ||
break | ||
case UIRectEdge.bottom: | ||
border.frame = CGRect.init(x: 0, y: frame.height - width, width: frame.width, height: width) | ||
break | ||
case UIRectEdge.left: | ||
border.frame = CGRect.init(x: 0, y: 0, width: width, height: frame.height) | ||
break | ||
case UIRectEdge.right: | ||
border.frame = CGRect.init(x: frame.width - width, y: 0, width: width, height: frame.height) | ||
break | ||
default: | ||
break | ||
} | ||
|
||
border.backgroundColor = color.cgColor | ||
self.addSublayer(border) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// UIView+.swift | ||
// Rx | ||
// | ||
// Created by taehy.k on 2021/08/31. | ||
// | ||
|
||
/* | ||
makeRounded 사용법) | ||
cornerView.makeRounded(cornerRadius: 50, maskedCorners: [.layerMinXMinYCorner, .layerMaxXMinYCorner]) | ||
|
||
모서리) X: 좌우, Y: 상하 로 생각하면 어렵지 않음 | ||
- layerMinXMinYCorner : 왼쪽 상단 | ||
- layerMaxXMinYCorner : 오른쪽 상단 | ||
- layerMinXMaxYCorner : 왼쪽 하단 | ||
- layerMaxXMaxYCorner : 오른쪽 하단 | ||
*/ | ||
|
||
import UIKit | ||
|
||
extension UIView { | ||
// Set Rounded View | ||
func makeRounded(cornerRadius: CGFloat?, maskedCorners: CACornerMask = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMinXMinYCorner]) { | ||
|
||
if let cornerRadius_ = cornerRadius { | ||
layer.cornerRadius = cornerRadius_ | ||
} else { | ||
layer.cornerRadius = layer.frame.height / 2 | ||
} | ||
|
||
layer.masksToBounds = true | ||
layer.maskedCorners = CACornerMask(arrayLiteral: maskedCorners) | ||
} | ||
} |