Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangyongji
/
MRFramework
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
03f5b0f0
authored
Sep 02, 2019
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整扩展逻辑
parent
0d0fa55d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
13 deletions
+39
-13
MRFramework/MRFramework/Extensions/UIKit/CAGradientLayer+util.swift
+21
-13
MRFramework/MRFramework/Extensions/UIKit/UIScreen+util.swift
+18
-0
No files found.
MRFramework/MRFramework/Extensions/UIKit/CAGradientLayer+util.swift
View file @
03f5b0f0
...
@@ -12,9 +12,9 @@ extension CAGradientLayer {
...
@@ -12,9 +12,9 @@ extension CAGradientLayer {
public
struct
RenderColor
{
public
struct
RenderColor
{
var
color
:
UIColor
var
color
:
UIColor
// 颜色所在位置,0.0~1.0
// 颜色所在位置,0.0~1.0
var
location
:
CG
Float
var
location
:
Float
init
(
color
:
UIColor
,
location
:
CG
Float
)
{
init
(
color
:
UIColor
,
location
:
Float
)
{
self
.
color
=
color
self
.
color
=
color
self
.
location
=
location
self
.
location
=
location
}
}
...
@@ -34,7 +34,11 @@ extension CAGradientLayer {
...
@@ -34,7 +34,11 @@ extension CAGradientLayer {
var
startPoint
:
CGPoint
{
var
startPoint
:
CGPoint
{
switch
self
{
switch
self
{
case
.
horizontal
,
.
vertical
,
.
adjectiveFromLeft
:
case
.
horizontal
:
return
CGPoint
(
x
:
0
,
y
:
0.5
)
case
.
vertical
:
return
CGPoint
(
x
:
0.5
,
y
:
0
)
case
.
adjectiveFromLeft
:
return
CGPoint
(
x
:
0
,
y
:
0
)
return
CGPoint
(
x
:
0
,
y
:
0
)
case
.
adjectiveFromRight
:
case
.
adjectiveFromRight
:
return
CGPoint
(
x
:
1
,
y
:
1
)
return
CGPoint
(
x
:
1
,
y
:
1
)
...
@@ -44,9 +48,9 @@ extension CAGradientLayer {
...
@@ -44,9 +48,9 @@ extension CAGradientLayer {
var
endPoint
:
CGPoint
{
var
endPoint
:
CGPoint
{
switch
self
{
switch
self
{
case
.
horizontal
(
let
f
):
case
.
horizontal
(
let
f
):
return
CGPoint
(
x
:
f
,
y
:
0
)
return
CGPoint
(
x
:
f
,
y
:
0
.5
)
case
.
vertical
(
let
f
):
case
.
vertical
(
let
f
):
return
CGPoint
(
x
:
0
,
y
:
f
)
return
CGPoint
(
x
:
0
.5
,
y
:
f
)
case
.
adjectiveFromLeft
(
let
f
):
case
.
adjectiveFromLeft
(
let
f
):
return
CGPoint
(
x
:
f
,
y
:
f
)
return
CGPoint
(
x
:
f
,
y
:
f
)
case
.
adjectiveFromRight
(
let
f
):
case
.
adjectiveFromRight
(
let
f
):
...
@@ -58,16 +62,20 @@ extension CAGradientLayer {
...
@@ -58,16 +62,20 @@ extension CAGradientLayer {
extension
CAGradientLayer
{
extension
CAGradientLayer
{
public
class
func
layer
(
with
colors
:
[
RenderColor
],
direction
:
RenderDirection
=
.
vertical
(
1
))
->
CAGradientLayer
{
public
class
func
layer
(
with
colors
:
[
RenderColor
],
direction
:
RenderDirection
=
.
vertical
(
1
))
->
CAGradientLayer
{
let
renderColors
=
colors
.
map
({
$0
.
color
.
cgColor
})
let
renderLocations
=
colors
.
map
({
NSNumber
(
value
:
Float
(
$0
.
location
))
})
let
layer
=
CAGradientLayer
()
let
layer
=
CAGradientLayer
()
layer
.
colors
=
renderColors
layer
.
config
(
colors
:
colors
,
direction
:
direction
)
layer
.
locations
=
renderLocations
layer
.
startPoint
=
direction
.
startPoint
layer
.
endPoint
=
direction
.
endPoint
return
layer
return
layer
}
}
public
func
config
(
colors
:
[
RenderColor
],
direction
:
RenderDirection
=
.
vertical
(
1
))
{
let
renderColors
=
colors
.
map
({
$0
.
color
.
cgColor
})
let
renderLocations
=
colors
.
map
({
NSNumber
(
value
:
$0
.
location
)
})
self
.
colors
=
renderColors
self
.
locations
=
renderLocations
self
.
startPoint
=
direction
.
startPoint
self
.
endPoint
=
direction
.
endPoint
}
}
}
MRFramework/MRFramework/Extensions/UIKit/UIScreen+util.swift
View file @
03f5b0f0
...
@@ -69,3 +69,21 @@ extension CGSize {
...
@@ -69,3 +69,21 @@ extension CGSize {
return
CGSize
(
width
:
lhs
.
width
*
rhs
.
width
,
height
:
lhs
.
height
*
rhs
.
height
)
return
CGSize
(
width
:
lhs
.
width
*
rhs
.
width
,
height
:
lhs
.
height
*
rhs
.
height
)
}
}
}
}
extension
CGPoint
{
public
static
func
+
(
lhs
:
CGPoint
,
rhs
:
CGFloat
)
->
CGPoint
{
return
CGPoint
(
x
:
lhs
.
x
+
rhs
,
y
:
lhs
.
y
+
rhs
)
}
public
static
func
+
(
lhs
:
CGPoint
,
rhs
:
CGPoint
)
->
CGPoint
{
return
CGPoint
(
x
:
lhs
.
x
+
rhs
.
x
,
y
:
lhs
.
y
+
rhs
.
y
)
}
public
static
func
*
(
lhs
:
CGPoint
,
rhs
:
CGFloat
)
->
CGPoint
{
return
CGPoint
(
x
:
lhs
.
x
*
rhs
,
y
:
lhs
.
y
*
rhs
)
}
public
static
func
*
(
lhs
:
CGPoint
,
rhs
:
CGPoint
)
->
CGPoint
{
return
CGPoint
(
x
:
lhs
.
x
*
rhs
.
x
,
y
:
lhs
.
y
*
rhs
.
y
)
}
}
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