From 13fdd0a519adba56afad035726a76233ab5bd71a Mon Sep 17 00:00:00 2001 From: tsuzukihashi Date: Fri, 13 Mar 2020 17:56:54 +0900 Subject: [PATCH] Add NeumorphismDentView --- NeumorphismUI.xcodeproj/project.pbxproj | 4 ++ Sources/CustomViews/NeumorphismDentView.swift | 50 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Sources/CustomViews/NeumorphismDentView.swift diff --git a/NeumorphismUI.xcodeproj/project.pbxproj b/NeumorphismUI.xcodeproj/project.pbxproj index 52fa9e5..00e9846 100644 --- a/NeumorphismUI.xcodeproj/project.pbxproj +++ b/NeumorphismUI.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ DA954C782411D9740052B8FF /* NeumorphismManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA954C772411D9740052B8FF /* NeumorphismManager.swift */; }; DA98731B240BDE7D0083EB5E /* HighlightableButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */; }; DAD95493241B4E0200D3F56E /* NeumorphismLabelButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */; }; + DAD95495241B740E00D3F56E /* NeumorphismDentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD95494241B740E00D3F56E /* NeumorphismDentView.swift */; }; OBJ_30 /* ColorTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* ColorTransformer.swift */; }; OBJ_31 /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* ColorExtension.swift */; }; OBJ_32 /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* ViewExtension.swift */; }; @@ -65,6 +66,7 @@ DA954C772411D9740052B8FF /* NeumorphismManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManager.swift; sourceTree = ""; }; DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightableButton.swift; sourceTree = ""; }; DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismLabelButton.swift; sourceTree = ""; }; + DAD95494241B740E00D3F56E /* NeumorphismDentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismDentView.swift; sourceTree = ""; }; "NeumorphismUI::NeumorphismUI::Product" /* NeumorphismUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = NeumorphismUI.framework; sourceTree = BUILT_PRODUCTS_DIR; }; "NeumorphismUI::NeumorphismUITests::Product" /* NeumorphismUITests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = NeumorphismUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; OBJ_11 /* ColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = ""; }; @@ -124,6 +126,7 @@ isa = PBXGroup; children = ( DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */, + DAD95494241B740E00D3F56E /* NeumorphismDentView.swift */, DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */, DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */, ); @@ -288,6 +291,7 @@ OBJ_32 /* ViewExtension.swift in Sources */, OBJ_33 /* NeumorphismShadowModifier.swift in Sources */, DA5AFACF241833430098E0BB /* AnyShape.swift in Sources */, + DAD95495241B740E00D3F56E /* NeumorphismDentView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/CustomViews/NeumorphismDentView.swift b/Sources/CustomViews/NeumorphismDentView.swift new file mode 100644 index 0000000..0d4c9a3 --- /dev/null +++ b/Sources/CustomViews/NeumorphismDentView.swift @@ -0,0 +1,50 @@ +import SwiftUI + +@available(iOS 13.0.0, *) +public struct NeumorphismDentView: View { + @EnvironmentObject var neumorphism: NeumorphismManager + + private let width: CGFloat + private let height: CGFloat + private let cornerRadius: CGFloat + + public init( + width: CGFloat = 100, + height: CGFloat = 100, + cornerRadius: CGFloat = 16 + ) { + self.width = width + self.height = height + self.cornerRadius = cornerRadius + } + + public var body: some View { + ZStack{ + RoundedRectangle(cornerRadius: self.cornerRadius) + .fill(self.neumorphism.color) + .frame(width: self.width, height: self.height) + .overlay( + RoundedRectangle(cornerRadius: self.cornerRadius) + .stroke(self.neumorphism.color, lineWidth: 4) + .shadow(color: self.neumorphism.color.darkerColor(), radius: 4, x: 4, y: 4) + .clipShape(RoundedRectangle(cornerRadius: self.cornerRadius)) + .shadow(color: self.neumorphism.color.lighterColor(), radius: 2, x: -2, y: -2) + .clipShape(RoundedRectangle(cornerRadius: self.cornerRadius)) + ) + .cornerRadius(self.cornerRadius) + } + } +} + +@available(iOS 13.0.0, *) +struct NeumorphismTextView_Previews: PreviewProvider { + static let neumorphism = NeumorphismManager( + lightColor: Color(hex: "C1D2EB"), + darkColor: Color(hex: "2C292C") + ) + static var previews: some View { + NeumorphismDentView() + .environmentObject(neumorphism) + .previewLayout(.sizeThatFits) + } +}