Commit deb55b80 by Dmitriy Stepanets

Working on button shadows

parent 2665b8a0
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */; }; CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */; };
CDE18DD425D169A500C80ED9 /* PrimaryColorsAsset.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CDE18DD325D169A500C80ED9 /* PrimaryColorsAsset.xcassets */; }; CDE18DD425D169A500C80ED9 /* PrimaryColorsAsset.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CDE18DD325D169A500C80ED9 /* PrimaryColorsAsset.xcassets */; };
CDE18DD825D16CB200C80ED9 /* NavigationCityButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */; }; CDE18DD825D16CB200C80ED9 /* NavigationCityButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */; };
CDFDAC6A25D406DA00754945 /* NeoButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDFDAC6925D406DA00754945 /* NeoButton.swift */; };
CEAD00A12577B2D5003596AD /* StuffThatIsPresentInTheMainProject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEAD00A02577B2D5003596AD /* StuffThatIsPresentInTheMainProject.swift */; }; CEAD00A12577B2D5003596AD /* StuffThatIsPresentInTheMainProject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEAD00A02577B2D5003596AD /* StuffThatIsPresentInTheMainProject.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -85,6 +86,7 @@ ...@@ -85,6 +86,7 @@
CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastViewController.swift; sourceTree = "<group>"; }; CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastViewController.swift; sourceTree = "<group>"; };
CDE18DD325D169A500C80ED9 /* PrimaryColorsAsset.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = PrimaryColorsAsset.xcassets; sourceTree = "<group>"; }; CDE18DD325D169A500C80ED9 /* PrimaryColorsAsset.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = PrimaryColorsAsset.xcassets; sourceTree = "<group>"; };
CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationCityButton.swift; sourceTree = "<group>"; }; CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationCityButton.swift; sourceTree = "<group>"; };
CDFDAC6925D406DA00754945 /* NeoButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeoButton.swift; sourceTree = "<group>"; };
CEAD00A02577B2D5003596AD /* StuffThatIsPresentInTheMainProject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StuffThatIsPresentInTheMainProject.swift; sourceTree = "<group>"; }; CEAD00A02577B2D5003596AD /* StuffThatIsPresentInTheMainProject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StuffThatIsPresentInTheMainProject.swift; sourceTree = "<group>"; };
DF826CF4702D9DCCB9A9DD71 /* Pods-1Weather.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.release.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.release.xcconfig"; sourceTree = "<group>"; }; DF826CF4702D9DCCB9A9DD71 /* Pods-1Weather.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.release.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -199,6 +201,7 @@ ...@@ -199,6 +201,7 @@
children = ( children = (
CD6B303A2572680C004B34B3 /* SelfSizingButton.swift */, CD6B303A2572680C004B34B3 /* SelfSizingButton.swift */,
CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */, CDE18DD725D16CB200C80ED9 /* NavigationCityButton.swift */,
CDFDAC6925D406DA00754945 /* NeoButton.swift */,
); );
path = Buttons; path = Buttons;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -431,6 +434,7 @@ ...@@ -431,6 +434,7 @@
870880232578ED190076BFB1 /* WdtCondition.swift in Sources */, 870880232578ED190076BFB1 /* WdtCondition.swift in Sources */,
CD1237F1255D83C500C98139 /* UIColor+Hex.swift in Sources */, CD1237F1255D83C500C98139 /* UIColor+Hex.swift in Sources */,
870880212578ED190076BFB1 /* WdtDaySummary.swift in Sources */, 870880212578ED190076BFB1 /* WdtDaySummary.swift in Sources */,
CDFDAC6A25D406DA00754945 /* NeoButton.swift in Sources */,
8708801C2578DDD50076BFB1 /* WdtLocation.swift in Sources */, 8708801C2578DDD50076BFB1 /* WdtLocation.swift in Sources */,
CDD0F1EE25725BCF00CF5017 /* ThemeManager.swift in Sources */, CDD0F1EE25725BCF00CF5017 /* ThemeManager.swift in Sources */,
CD1237F4255D889F00C98139 /* GradientView.swift in Sources */, CD1237F4255D889F00C98139 /* GradientView.swift in Sources */,
......
...@@ -8,8 +8,16 @@ ...@@ -8,8 +8,16 @@
import UIKit import UIKit
extension UIColor { extension UIColor {
private var isDarkColor: Bool {
var r, g, b, a: CGFloat
(r, g, b, a) = (0, 0, 0, 0)
self.getRed(&r, green: &g, blue: &b, alpha: &a)
let lum = 0.2126 * r + 0.7152 * g + 0.0722 * b
return lum < 0.60 ? true : false
}
var highlighted:UIColor { var highlighted:UIColor {
return self.adjust(by: -30) return self.isDarkColor ? self.adjust(by: 30) : self.adjust(by: -30)
} }
private func adjust(by percentage:CGFloat=30.0) -> UIColor { private func adjust(by percentage:CGFloat=30.0) -> UIColor {
......
{
"images" : [
{
"filename" : "bell.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
{
"images" : [
{
"filename" : "city_pin.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
{
"images" : [
{
"filename" : "down_arrow.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
"color-space" : "srgb", "color-space" : "srgb",
"components" : { "components" : {
"alpha" : "1.000", "alpha" : "1.000",
"blue" : "0.078", "blue" : "0x13",
"green" : "0.075", "green" : "0x13",
"red" : "0.075" "red" : "0x13"
} }
}, },
"idiom" : "universal" "idiom" : "universal"
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
"color-space" : "srgb", "color-space" : "srgb",
"components" : { "components" : {
"alpha" : "1.000", "alpha" : "1.000",
"blue" : "1.000", "blue" : "0x13",
"green" : "1.000", "green" : "0x13",
"red" : "1.000" "red" : "0x13"
} }
}, },
"idiom" : "universal" "idiom" : "universal"
......
...@@ -7,39 +7,70 @@ ...@@ -7,39 +7,70 @@
import UIKit import UIKit
class NavigationCityButton: UIView { class NavigationCityButton: UIButton {
//Private //Private
private let locationIcon = UIImageView() private let downArrowImageView = UIImageView()
private let button = SelfSizingButton() private let kSpaceForDownArrow:CGFloat = 10
//Public
var onButtonTouch:(() -> Void)?
init() { init() {
super.init(frame: .zero) super.init(frame: .zero)
prepareIcon() contentHorizontalAlignment = .left
preparePinImage()
prepareTitle()
prepareDownArrow()
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
return CGSize(width: size.width + titleEdgeInsets.left + titleEdgeInsets.right + kSpaceForDownArrow,
height: size.height + titleEdgeInsets.top + titleEdgeInsets.bottom)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
tintColor = ThemeManager.currentTheme.primaryTextColor.highlighted
downArrowImageView.tintColor = self.tintColor
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
tintColor = ThemeManager.currentTheme.primaryTextColor
downArrowImageView.tintColor = self.tintColor
}
} }
private extension NavigationCityButton { private extension NavigationCityButton {
func prepareIcon() { func preparePinImage() {
locationIcon.backgroundColor = .red setImage(UIImage(named: "city_pin.pdf"), for: .normal)
addSubview(locationIcon) tintColor = ThemeManager.currentTheme.primaryTextColor
}
func prepareTitle() {
titleEdgeInsets = .init(top: 0, left: 8, bottom: 0, right: 0)
titleLabel?.font = AppFont.SFPro.regular(size: 16)
setTitleColor(ThemeManager.currentTheme.primaryTextColor, for: .normal)
setTitleColor(ThemeManager.currentTheme.primaryTextColor.highlighted, for: .highlighted)
}
func prepareDownArrow() {
downArrowImageView.image = UIImage(named: "down_arrow")
downArrowImageView.tintColor = self.tintColor
downArrowImageView.contentMode = .scaleAspectFit
addSubview(downArrowImageView)
locationIcon.snp.makeConstraints { (make) in downArrowImageView.snp.makeConstraints { (make) in
make.left.equalToSuperview().inset(16) make.size.equalTo(CGSize(width: 12, height: 12))
make.right.equalToSuperview()
make.centerY.equalToSuperview() make.centerY.equalToSuperview()
make.size.equalTo(CGSize(width: 18, height: 18))
} }
} }
func prepareButton() {
button.setTitle("New York", for: .normal)
button
}
} }
//
// NeoButton.swift
// 1Weather
//
// Created by Dmitry Stepanets on 10.02.2021.
//
import UIKit
class NeoButton: UIButton {
private let backgroundLayer = CALayer()
private let outerDarkShadow = CALayer()
private let outerLightShadow = CALayer()
init() {
super.init(frame: .zero)
prepareOuterShadows()
prepareBackgroundLayer()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
self.backgroundLayer.frame = self.bounds
self.refreshShadows()
}
private func refreshShadows() {
outerLightShadow.shadowPath = UIBezierPath(rect: self.bounds).cgPath
outerLightShadow.masksToBounds = false
outerLightShadow.shadowColor = UIColor.white.cgColor
outerLightShadow.shadowOpacity = 0.5
outerLightShadow.shadowOffset = .init(width: -10, height: -10)
outerLightShadow.shadowRadius = 8
outerDarkShadow.shadowPath = UIBezierPath(rect: self.bounds).cgPath
outerDarkShadow.masksToBounds = false
outerDarkShadow.shadowColor = UIColor(hex: 0xe7e9fc).cgColor
outerDarkShadow.shadowOpacity = 1
outerDarkShadow.shadowOffset = .init(width: 6, height: 6)
outerDarkShadow.shadowRadius = 8
}
// private func addDropShadow(color: UIColor, offset: CGSize, btnLayer : CALayer) {
// testLayer.masksToBounds = false
// testLayer.shadowColor = color.cgColor
// testLayer.shadowOpacity = 0.2
// testLayer.shadowOffset = offset
// testLayer.shadowRadius = 4
//
//// btnLayer.masksToBounds = false
//// btnLayer.shadowColor = color.cgColor
//// btnLayer.shadowOpacity = 1
//// btnLayer.shadowOffset = offset
//// btnLayer.shadowRadius = 4
// }
}
private extension NeoButton {
private func prepareOuterShadows() {
layer.insertSublayer(outerLightShadow, at: 0)
layer.insertSublayer(outerDarkShadow, at: 0)
}
private func prepareBackgroundLayer() {
layer.backgroundColor = UIColor.red.cgColor
layer.addSublayer(backgroundLayer)
}
}
...@@ -29,6 +29,6 @@ struct DefaultTheme: ThemeProtocol { ...@@ -29,6 +29,6 @@ struct DefaultTheme: ThemeProtocol {
} }
var primaryTextColor: UIColor { var primaryTextColor: UIColor {
return .white return UIColor(named: "primary_font") ?? .red
} }
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// //
import UIKit import UIKit
import Synth
class TodayViewController: UIViewController { class TodayViewController: UIViewController {
...@@ -15,11 +16,42 @@ class TodayViewController: UIViewController { ...@@ -15,11 +16,42 @@ class TodayViewController: UIViewController {
view.backgroundColor = UIColor(named: "primary_color") view.backgroundColor = UIColor(named: "primary_color")
prepareNavigationBar() prepareNavigationBar()
} }
@objc private func handleCityButton() {
}
@objc private func handleNotificationButton() {
}
} }
private extension TodayViewController { private extension TodayViewController {
func prepareNavigationBar() { func prepareNavigationBar() {
let cityButton = SelfSizingButton() //City button
cityButton.tit let cityButton = NavigationCityButton()
cityButton.setTitle("New York", for: .normal)
cityButton.sizeToFit()
cityButton.addTarget(self, action: #selector(handleCityButton), for: .touchUpInside)
let cityBarItem = UIBarButtonItem(customView: cityButton)
let barSpacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
barSpacer.width = 18
//Notification button
let notificationButton = NeoButton()
notificationButton.setImage(UIImage(named: "bell"), for: .normal)
notificationButton.tintColor = ThemeManager.currentTheme.primaryTextColor
notificationButton.frame = .init(origin: .zero, size: CGSize(width: 42, height: 42))
notificationButton.addTarget(self, action: #selector(handleNotificationButton), for: .touchUpInside)
// let notificationBarItem = UIBarButtonItem(customView: notificationButton)
view.addSubview(notificationButton)
notificationButton.snp.makeConstraints { (make) in
make.size.equalTo(CGSize(width: 42, height: 42))
make.center.equalToSuperview()
}
self.navigationItem.leftBarButtonItems = [barSpacer, cityBarItem]
// self.navigationItem.rightBarButtonItem = notificationBarItem
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment