Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
8ce654f0
Commit
8ce654f0
authored
Feb 11, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Finished NeoButton UI
- Working with NeoButton highlighted state
parent
deb55b80
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
42 deletions
+108
-42
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
1Weather/Resources/PrimaryColorsAsset.xcassets/primary_color.colorset/Contents.json
+3
-3
1Weather/UI/Buttons/NeoButton.swift
+101
-32
1Weather/UI/Helpers/ThemeManager.swift
+1
-0
1Weather/UI/View controllers/Today/TodayViewController.swift
+3
-7
No files found.
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
View file @
8ce654f0
No preview for this file type
1Weather/Resources/PrimaryColorsAsset.xcassets/primary_color.colorset/Contents.json
View file @
8ce654f0
...
@@ -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"
:
"
254
"
,
"green"
:
"
1.000
"
,
"green"
:
"
248
"
,
"red"
:
"
1.000
"
"red"
:
"
247
"
}
}
},
},
"idiom"
:
"universal"
"idiom"
:
"universal"
...
...
1Weather/UI/Buttons/NeoButton.swift
View file @
8ce654f0
...
@@ -8,14 +8,40 @@
...
@@ -8,14 +8,40 @@
import
UIKit
import
UIKit
class
NeoButton
:
UIButton
{
class
NeoButton
:
UIButton
{
//Private
private
let
lightColor
=
UIColor
.
white
private
let
darkColor
=
UIColor
(
hex
:
0xe7e9fc
)
private
let
backgroundLayer
=
CALayer
()
private
let
backgroundLayer
=
CALayer
()
private
let
outerDarkShadow
=
CALayer
()
private
let
highlightedGradientLayer
=
CAGradientLayer
()
private
let
outerLightShadow
=
CALayer
()
private
let
outerDarkShadowLayer
=
CALayer
()
private
let
outerLightShadowLayer
=
CALayer
()
private
let
borderGradient
=
CAGradientLayer
()
private
let
borderLayer
=
CAShapeLayer
()
private
var
cornerRadiusObserver
:
NSKeyValueObservation
?
private
var
highlightedObserver
:
NSKeyValueObservation
?
init
()
{
init
()
{
super
.
init
(
frame
:
.
zero
)
super
.
init
(
frame
:
.
zero
)
prepareOuterShadows
()
prepareBackgroundLayer
()
prepareBackgroundLayer
()
prepareHighlightedGradient
()
prepareOuterShadows
()
prepareBorderLayer
()
prepareObservers
()
}
override
var
backgroundColor
:
UIColor
?
{
get
{
guard
let
color
=
backgroundLayer
.
backgroundColor
else
{
return
nil
}
return
UIColor
(
cgColor
:
color
)
}
set
{
self
.
backgroundLayer
.
backgroundColor
=
newValue
?
.
cgColor
}
}
}
required
init
?(
coder
:
NSCoder
)
{
required
init
?(
coder
:
NSCoder
)
{
...
@@ -26,48 +52,91 @@ class NeoButton: UIButton {
...
@@ -26,48 +52,91 @@ class NeoButton: UIButton {
super
.
layoutSubviews
()
super
.
layoutSubviews
()
self
.
backgroundLayer
.
frame
=
self
.
bounds
self
.
backgroundLayer
.
frame
=
self
.
bounds
self
.
borderGradient
.
frame
=
self
.
bounds
self
.
borderLayer
.
path
=
UIBezierPath
(
roundedRect
:
self
.
bounds
,
cornerRadius
:
self
.
layer
.
cornerRadius
)
.
cgPath
self
.
refreshShadows
()
self
.
refreshShadows
()
self
.
updateHighlightedGradient
()
}
}
//Public
//Private
private
func
refreshShadows
()
{
private
func
refreshShadows
()
{
outerLightShadow
.
shadowPath
=
UIBezierPath
(
rect
:
self
.
bounds
)
.
cgPath
outerLightShadow
Layer
.
shadowPath
=
UIBezierPath
(
rect
:
self
.
bounds
)
.
cgPath
outerLightShadow
.
masksToBounds
=
false
outerLightShadow
Layer
.
masksToBounds
=
false
outerLightShadow
.
shadowColor
=
UIColor
.
white
.
cgColor
outerLightShadow
Layer
.
shadowColor
=
lightColor
.
cgColor
outerLightShadow
.
shadowOpacity
=
0.5
outerLightShadow
Layer
.
shadowOpacity
=
0.5
outerLightShadow
.
shadowOffset
=
.
init
(
width
:
-
10
,
height
:
-
10
)
outerLightShadow
Layer
.
shadowOffset
=
.
init
(
width
:
-
10
,
height
:
-
10
)
outerLightShadow
.
shadowRadius
=
8
outerLightShadow
Layer
.
shadowRadius
=
8
outerDarkShadow
.
shadowPath
=
UIBezierPath
(
rect
:
self
.
bounds
)
.
cgPath
outerDarkShadow
Layer
.
shadowPath
=
UIBezierPath
(
rect
:
self
.
bounds
)
.
cgPath
outerDarkShadow
.
masksToBounds
=
false
outerDarkShadow
Layer
.
masksToBounds
=
false
outerDarkShadow
.
shadowColor
=
UIColor
(
hex
:
0xe7e9fc
)
.
cgColor
outerDarkShadow
Layer
.
shadowColor
=
darkColor
.
cgColor
outerDarkShadow
.
shadowOpacity
=
1
outerDarkShadow
Layer
.
shadowOpacity
=
1
outerDarkShadow
.
shadowOffset
=
.
init
(
width
:
6
,
height
:
6
)
outerDarkShadow
Layer
.
shadowOffset
=
.
init
(
width
:
6
,
height
:
6
)
outerDarkShadow
.
shadowRadius
=
8
outerDarkShadow
Layer
.
shadowRadius
=
8
}
}
// private func addDropShadow(color: UIColor, offset: CGSize, btnLayer : CALayer) {
private
func
updateHighlightedGradient
()
{
// testLayer.masksToBounds = false
guard
!
self
.
bounds
.
isEmpty
else
{
return
}
// testLayer.shadowColor = color.cgColor
// testLayer.shadowOpacity = 0.2
self
.
highlightedGradientLayer
.
frame
=
self
.
bounds
// testLayer.shadowOffset = offset
// testLayer.shadowRadius = 4
let
hypotenuse
=
sqrt
(
pow
(
bounds
.
size
.
width
,
2
)
+
pow
(
bounds
.
size
.
height
,
2
))
//
// area of square = height * width = hypotenuse * (maximum distance length perpendicular to hypotenuse)
//// btnLayer.masksToBounds = false
let
heightOfGradient
=
(
bounds
.
size
.
width
*
bounds
.
size
.
height
*
2
)
/
hypotenuse
//// btnLayer.shadowColor = color.cgColor
let
angleInRadians
=
atan
(
bounds
.
size
.
height
/
bounds
.
size
.
width
)
//// btnLayer.shadowOpacity = 1
//// btnLayer.shadowOffset = offset
let
newBounds
=
CGRect
(
x
:
bounds
.
size
.
width
,
y
:
bounds
.
size
.
height
,
width
:
hypotenuse
,
height
:
heightOfGradient
)
//// btnLayer.shadowRadius = 4
self
.
highlightedGradientLayer
.
bounds
=
newBounds
// }
self
.
highlightedGradientLayer
.
setAffineTransform
(
CGAffineTransform
(
rotationAngle
:
-
angleInRadians
))
}
}
}
private
extension
NeoButton
{
private
extension
NeoButton
{
private
func
prepareOuterShadows
()
{
private
func
prepareOuterShadows
()
{
layer
.
insertSublayer
(
outerLightShadow
,
at
:
0
)
layer
.
insertSublayer
(
outerLightShadow
Layer
,
below
:
backgroundLayer
)
layer
.
insertSublayer
(
outerDarkShadow
,
at
:
0
)
layer
.
insertSublayer
(
outerDarkShadow
Layer
,
below
:
backgroundLayer
)
}
}
private
func
prepareBackgroundLayer
()
{
private
func
prepareBackgroundLayer
()
{
layer
.
backgroundColor
=
UIColor
.
red
.
cgColor
self
.
backgroundColor
=
.
clear
layer
.
addSublayer
(
backgroundLayer
)
self
.
backgroundLayer
.
masksToBounds
=
true
layer
.
insertSublayer
(
backgroundLayer
,
below
:
self
.
imageView
?
.
layer
)
}
private
func
prepareHighlightedGradient
()
{
self
.
highlightedGradientLayer
.
colors
=
[
self
.
backgroundColor
!.
cgColor
,
self
.
darkColor
.
cgColor
]
self
.
highlightedGradientLayer
.
startPoint
=
.
zero
self
.
highlightedGradientLayer
.
endPoint
=
.
init
(
x
:
0
,
y
:
1
)
self
.
highlightedGradientLayer
.
isHidden
=
true
backgroundLayer
.
addSublayer
(
self
.
highlightedGradientLayer
)
}
private
func
prepareBorderLayer
()
{
borderGradient
.
colors
=
[
UIColor
.
white
.
cgColor
,
UIColor
.
white
.
withAlphaComponent
(
0.15
)
.
cgColor
]
borderLayer
.
lineWidth
=
1
/
UIScreen
.
main
.
scale
borderLayer
.
strokeColor
=
UIColor
.
black
.
cgColor
borderLayer
.
fillColor
=
UIColor
.
clear
.
cgColor
borderGradient
.
mask
=
borderLayer
self
.
layer
.
addSublayer
(
borderGradient
)
}
private
func
prepareObservers
()
{
cornerRadiusObserver
=
observe
(
\
NeoButton
.
layer
.
cornerRadius
,
options
:
.
new
,
changeHandler
:
{
(
button
,
change
)
in
self
.
backgroundLayer
.
cornerRadius
=
change
.
newValue
??
0
self
.
borderGradient
.
cornerRadius
=
change
.
newValue
??
0
})
highlightedObserver
=
observe
(
\
NeoButton
.
isHighlighted
,
options
:
.
new
,
changeHandler
:
{
(
button
,
change
)
in
print
(
"isHighlighted:
\(
change
.
newValue
)
"
)
guard
let
state
=
change
.
newValue
else
{
return
}
self
.
highlightedGradientLayer
.
isHidden
=
!
state
})
}
}
}
}
1Weather/UI/Helpers/ThemeManager.swift
View file @
8ce654f0
...
@@ -25,5 +25,6 @@ public struct ThemeManager {
...
@@ -25,5 +25,6 @@ public struct ThemeManager {
UINavigationBar
.
appearance
()
.
barTintColor
=
currentTheme
.
navigationBarBackgroundColor
UINavigationBar
.
appearance
()
.
barTintColor
=
currentTheme
.
navigationBarBackgroundColor
UINavigationBar
.
appearance
()
.
isTranslucent
=
false
UINavigationBar
.
appearance
()
.
isTranslucent
=
false
UINavigationBar
.
appearance
()
.
tintColor
=
currentTheme
.
navigationTintColor
UINavigationBar
.
appearance
()
.
tintColor
=
currentTheme
.
navigationTintColor
UINavigationBar
.
appearance
()
.
shadowImage
=
UIImage
()
}
}
}
}
1Weather/UI/View controllers/Today/TodayViewController.swift
View file @
8ce654f0
...
@@ -40,18 +40,14 @@ private extension TodayViewController {
...
@@ -40,18 +40,14 @@ private extension TodayViewController {
//Notification button
//Notification button
let
notificationButton
=
NeoButton
()
let
notificationButton
=
NeoButton
()
notificationButton
.
backgroundColor
=
UIColor
(
hex
:
0xf4f5fb
)
notificationButton
.
setImage
(
UIImage
(
named
:
"bell"
),
for
:
.
normal
)
notificationButton
.
setImage
(
UIImage
(
named
:
"bell"
),
for
:
.
normal
)
notificationButton
.
tintColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
notificationButton
.
tintColor
=
ThemeManager
.
currentTheme
.
primaryTextColor
notificationButton
.
frame
=
.
init
(
origin
:
.
zero
,
size
:
CGSize
(
width
:
42
,
height
:
42
))
notificationButton
.
frame
=
.
init
(
origin
:
.
zero
,
size
:
CGSize
(
width
:
42
,
height
:
42
))
notificationButton
.
layer
.
cornerRadius
=
4
notificationButton
.
addTarget
(
self
,
action
:
#selector(
handleNotificationButton
)
,
for
:
.
touchUpInside
)
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
.
leftBarButtonItems
=
[
barSpacer
,
cityBarItem
]
// self.navigationItem.rightBarButtonItem = notificationBarItem
self
.
navigationItem
.
rightBarButtonItem
=
UIBarButtonItem
(
customView
:
notificationButton
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment