Skip to content

Commit

Permalink
➕[ADD] : Radius, Shadow 익스텐션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Taehyeon-Kim committed Aug 31, 2021
1 parent e75c857 commit b3e59fd
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Basic-Exercise/Rx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
BD8CC47B26DE2A1300BCAEC3 /* CellSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8CC47A26DE2A1300BCAEC3 /* CellSample.swift */; };
BD8CC47D26DE2A2300BCAEC3 /* ComponentSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8CC47C26DE2A2300BCAEC3 /* ComponentSample.swift */; };
BD8CC47F26DE2A4000BCAEC3 /* XibSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8CC47E26DE2A4000BCAEC3 /* XibSample.swift */; };
BD8CC48126DE317400BCAEC3 /* UIView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8CC48026DE317400BCAEC3 /* UIView+.swift */; };
BD8CC48326DE31C500BCAEC3 /* CALayer+.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8CC48226DE31C500BCAEC3 /* CALayer+.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -45,6 +47,8 @@
BD8CC47A26DE2A1300BCAEC3 /* CellSample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellSample.swift; sourceTree = "<group>"; };
BD8CC47C26DE2A2300BCAEC3 /* ComponentSample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComponentSample.swift; sourceTree = "<group>"; };
BD8CC47E26DE2A4000BCAEC3 /* XibSample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XibSample.swift; sourceTree = "<group>"; };
BD8CC48026DE317400BCAEC3 /* UIView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+.swift"; sourceTree = "<group>"; };
BD8CC48226DE31C500BCAEC3 /* CALayer+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CALayer+.swift"; sourceTree = "<group>"; };
E2ECCA8A156648394D363D77 /* Pods-Rx.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rx.debug.xcconfig"; path = "Target Support Files/Pods-Rx/Pods-Rx.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -218,6 +222,8 @@
isa = PBXGroup;
children = (
BD8CC47226DE29E300BCAEC3 /* ExtensionSample.swift */,
BD8CC48026DE317400BCAEC3 /* UIView+.swift */,
BD8CC48226DE31C500BCAEC3 /* CALayer+.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -343,9 +349,11 @@
7007CD9526D5947300104F3C /* ObservableViewController.swift in Sources */,
BD8CC47B26DE2A1300BCAEC3 /* CellSample.swift in Sources */,
7007CD9726D5A76900104F3C /* TransfomationViewController.swift in Sources */,
BD8CC48326DE31C500BCAEC3 /* CALayer+.swift in Sources */,
7007CD8126D5916700104F3C /* AppDelegate.swift in Sources */,
7007CD8326D5916700104F3C /* SceneDelegate.swift in Sources */,
BD8CC47726DE29F800BCAEC3 /* ModelSample.swift in Sources */,
BD8CC48126DE317400BCAEC3 /* UIView+.swift in Sources */,
BD8CC47D26DE2A2300BCAEC3 /* ComponentSample.swift in Sources */,
BD8CC47F26DE2A4000BCAEC3 /* XibSample.swift in Sources */,
);
Expand Down
52 changes: 52 additions & 0 deletions Basic-Exercise/Rx/Source/Extensions/CALayer+.swift
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)
}
}
}
34 changes: 34 additions & 0 deletions Basic-Exercise/Rx/Source/Extensions/UIView+.swift
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)
}
}

0 comments on commit b3e59fd

Please sign in to comment.