Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PhoneManager
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yang
PhoneManager
Commits
46352455
Commit
46352455
authored
May 22, 2025
by
shenyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
d0f6a780
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
UIView+AZGradient.m
PhoneManager/Class/Tool/Class/OC/UIView+AZGradient.m
+96
-0
No files found.
PhoneManager/Class/Tool/Class/OC/UIView+AZGradient.m
0 → 100755
View file @
46352455
//
// UIView+AZGradient.m
// AZCategory
//
// Created by Alfred Zhang on 2017/6/29.
// Copyright © 2017年 Alfred Zhang. All rights reserved.
//
#import "UIView+AZGradient.h"
#import <objc/runtime.h>
@implementation
UIView
(
AZGradient
)
+
(
Class
)
layerClass
{
return
[
CAGradientLayer
class
];
}
+
(
UIView
*
)
az_gradientViewWithColors
:
(
NSArray
<
UIColor
*>
*
)
colors
locations
:
(
NSArray
<
NSNumber
*>
*
)
locations
startPoint
:
(
CGPoint
)
startPoint
endPoint
:
(
CGPoint
)
endPoint
{
UIView
*
view
=
[[
self
alloc
]
init
];
[
view
az_setGradientBackgroundWithColors
:
colors
locations
:
locations
startPoint
:
startPoint
endPoint
:
endPoint
];
return
view
;
}
-
(
void
)
az_setGradientBackgroundWithColors
:
(
NSArray
<
UIColor
*>
*
)
colors
locations
:
(
NSArray
<
NSNumber
*>
*
)
locations
startPoint
:
(
CGPoint
)
startPoint
endPoint
:
(
CGPoint
)
endPoint
{
NSMutableArray
*
colorsM
=
[
NSMutableArray
array
];
for
(
UIColor
*
color
in
colors
)
{
[
colorsM
addObject
:(
__bridge
id
)
color
.
CGColor
];
}
self
.
az_colors
=
[
colorsM
copy
];
self
.
az_locations
=
locations
;
self
.
az_startPoint
=
startPoint
;
self
.
az_endPoint
=
endPoint
;
}
#pragma mark- Getter&Setter
-
(
NSArray
*
)
az_colors
{
return
objc_getAssociatedObject
(
self
,
_cmd
);
}
-
(
void
)
setAz_colors
:
(
NSArray
*
)
colors
{
objc_setAssociatedObject
(
self
,
@selector
(
az_colors
),
colors
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[((
CAGradientLayer
*
)
self
.
layer
)
setColors
:
self
.
az_colors
];
}
}
-
(
NSArray
<
NSNumber
*>
*
)
az_locations
{
return
objc_getAssociatedObject
(
self
,
_cmd
);
}
-
(
void
)
setAz_locations
:
(
NSArray
<
NSNumber
*>
*
)
locations
{
objc_setAssociatedObject
(
self
,
@selector
(
az_locations
),
locations
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[((
CAGradientLayer
*
)
self
.
layer
)
setLocations
:
self
.
az_locations
];
}
}
-
(
CGPoint
)
az_startPoint
{
return
[
objc_getAssociatedObject
(
self
,
_cmd
)
CGPointValue
];
}
-
(
void
)
setAz_startPoint
:
(
CGPoint
)
startPoint
{
objc_setAssociatedObject
(
self
,
@selector
(
az_startPoint
),
[
NSValue
valueWithCGPoint
:
startPoint
],
OBJC_ASSOCIATION_RETAIN_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[((
CAGradientLayer
*
)
self
.
layer
)
setStartPoint
:
self
.
az_startPoint
];
}
}
-
(
CGPoint
)
az_endPoint
{
return
[
objc_getAssociatedObject
(
self
,
_cmd
)
CGPointValue
];
}
-
(
void
)
setAz_endPoint
:
(
CGPoint
)
endPoint
{
objc_setAssociatedObject
(
self
,
@selector
(
az_endPoint
),
[
NSValue
valueWithCGPoint
:
endPoint
],
OBJC_ASSOCIATION_RETAIN_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[((
CAGradientLayer
*
)
self
.
layer
)
setEndPoint
:
self
.
az_endPoint
];
}
}
@end
@implementation
UILabel
(
AZGradient
)
+
(
Class
)
layerClass
{
return
[
CAGradientLayer
class
];
}
@end
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