Skip to content

Commit

Permalink
Merge pull request #179 from baller784/button_shadow_fix
Browse files Browse the repository at this point in the history
[Build #130] Button shadow fix
  • Loading branch information
baller784 authored Nov 30, 2020
2 parents bb0de8f + e759a59 commit 595ff68
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Example/Authenticator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@
CODE_SIGN_ENTITLEMENTS = Authenticator_Example.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 129;
CURRENT_PROJECT_VERSION = 130;
DEVELOPMENT_TEAM = "";
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
Expand All @@ -2247,7 +2247,7 @@
CODE_SIGN_ENTITLEMENTS = Authenticator_Example.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 129;
CURRENT_PROJECT_VERSION = 130;
DEVELOPMENT_TEAM = "";
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
Expand Down
6 changes: 3 additions & 3 deletions Example/Authenticator/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.179",
"green" : "0.126",
"red" : "0.056"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
4 changes: 4 additions & 0 deletions Example/Authenticator/Utils/Extensions/ColorExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ extension UIColor {
static var redAlert: UIColor {
return UIColor(named: "redAlert", in: .authenticator_main, compatibleWith: nil)!
}

static var shadow: UIColor {
return UIColor(named: "shadow", in: .authenticator_main, compatibleWith: nil)!
}
}
24 changes: 13 additions & 11 deletions Example/Authenticator/Views/Components/CustomButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ class CustomButton: UIButton {
}
}

override func layoutSubviews() {
super.layoutSubviews()
layer.shadowPath = UIBezierPath(rect: bounds).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.main.scale
layer.shadowColor = UIColor.shadow.cgColor
layer.shadowOffset = CGSize(width: 0, height: 6)
layer.shadowOpacity = 0.2
layer.shadowRadius = 10.0
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.main.scale
}

init(text: String, height: CGFloat = Layout.height, textColor: UIColor = .white, backgroundColor: UIColor = .darkBlue) {
super.init(frame: .zero)
self.backgroundColor = backgroundColor
Expand All @@ -46,23 +59,12 @@ class CustomButton: UIButton {
setTitleColor(textColor, for: .highlighted)
layer.cornerRadius = Layout.cornerRadius
self.height(height)
setupShadow()
}

func updateTitle(text: String) {
setTitle(text, for: .normal)
}

private func setupShadow() {
layer.shadowPath = UIBezierPath(rect: bounds).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.main.scale
layer.shadowColor = UIColor(red: 0.051, green: 0.576, blue: 0.973, alpha: 0.2).cgColor
layer.shadowOffset = CGSize(width: 0, height: 6)
layer.shadowOpacity = 0.7
layer.shadowRadius = 30.0
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ class RoundedShadowView: UIView {

shadowLayer.shadowColor = UIColor(red: 0.056, green: 0.126, blue: 0.179, alpha: 0.12).cgColor
shadowLayer.shadowPath = shadowLayer.path
shadowLayer.shadowOffset = CGSize(width: 0, height: 8)
shadowLayer.shadowOpacity = 0.9
shadowLayer.shadowRadius = 26
shadowLayer.shadowOffset = .zero
shadowLayer.shadowOpacity = 0.7
shadowLayer.shadowRadius = 8
shadowLayer.shadowPath = UIBezierPath(rect: bounds).cgPath

layer.insertSublayer(shadowLayer, at: 0)
}
Expand Down

0 comments on commit 595ff68

Please sign in to comment.