diff --git a/NeumorphismUI.xcodeproj/project.pbxproj b/NeumorphismUI.xcodeproj/project.pbxproj index 7f35099..52fa9e5 100644 --- a/NeumorphismUI.xcodeproj/project.pbxproj +++ b/NeumorphismUI.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ DA90AF682412D0EE00E759A9 /* NeumorphismManagerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA90AF672412D0EE00E759A9 /* NeumorphismManagerMock.swift */; }; 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 */; }; 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 */; }; @@ -63,6 +64,7 @@ DA90AF672412D0EE00E759A9 /* NeumorphismManagerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphismManagerMock.swift; sourceTree = ""; }; 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 = ""; }; "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 = ""; }; @@ -123,6 +125,7 @@ children = ( DA98731A240BDE7D0083EB5E /* HighlightableButton.swift */, DA5AFAC8241691210098E0BB /* NeumorphismButton.swift */, + DAD95492241B4E0200D3F56E /* NeumorphismLabelButton.swift */, ); path = CustomViews; sourceTree = ""; @@ -274,6 +277,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( + DAD95493241B4E0200D3F56E /* NeumorphismLabelButton.swift in Sources */, OBJ_30 /* ColorTransformer.swift in Sources */, OBJ_31 /* ColorExtension.swift in Sources */, DA98731B240BDE7D0083EB5E /* HighlightableButton.swift in Sources */, diff --git a/Sources/CustomViews/NeumorphismLabelButton.swift b/Sources/CustomViews/NeumorphismLabelButton.swift new file mode 100644 index 0000000..f124e67 --- /dev/null +++ b/Sources/CustomViews/NeumorphismLabelButton.swift @@ -0,0 +1,70 @@ +import SwiftUI + +@available(iOS 13.0.0, *) +struct NeumorphismLabelButton: View { + @EnvironmentObject var neumorphism: NeumorphismManager + @State var isSelected = false + private var text: String + private var font: Font? + private var color: Color? + private var width: CGFloat + private var height: CGFloat + private var cornerRadius: CGFloat + private var handler: (() -> Void)? + + public init + ( + text: String = "Button", + font: Font? = nil, + color: Color? = nil, + width: CGFloat = 100, + height: CGFloat = 100, + cornerRadius: CGFloat = 10, + handler: (() -> Void)? = nil + ) { + self.text = text + self.font = font + self.color = color + self.width = width + self.height = height + self.cornerRadius = cornerRadius + self.handler = handler + } + + public var body: some View { + HighlightableButton(action: { + self.isSelected.toggle() + self.handler?() + }) { isHeighlight in + ZStack { + RoundedRectangle(cornerRadius: self.cornerRadius) + .fill(self.neumorphism.color) + .frame(width: self.width, height: self.height) + .modifier(NeumorphismShadowModifier(isAnimation: isHeighlight)) + .padding() + + + Text(self.text) + .font(self.font ?? .title) + .foregroundColor( + isHeighlight ? self.color?.darkerColor() ?? self.neumorphism.color.darkerColor().darkerColor() : self.color ?? self.neumorphism.color.darkerColor()) + } + .animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1)) + } + .padding() + } +} + +@available(iOS 13.0.0, *) +struct NeumorphismLabelButton_Previews: PreviewProvider { + static let neumorphism = NeumorphismManager( + lightColor: Color(hex: "C1D2EB"), + darkColor: Color(hex: "2C292C") + ) + + static var previews: some View { + NeumorphismLabelButton() + .environmentObject(neumorphism) + .previewLayout(.sizeThatFits) + } +}