Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
GMAI
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMAI
Commits
e206ca72
Commit
e206ca72
authored
Jan 17, 2020
by
jz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add files
parent
ce25de58
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
687 additions
and
0 deletions
+687
-0
NSString+jsonData.h
GMAI/Classes/FaceAITool/NSString+jsonData.h
+56
-0
NSString+jsonData.m
GMAI/Classes/FaceAITool/NSString+jsonData.m
+106
-0
UIImage+GMExtension.h
GMAI/Classes/FaceAITool/UIImage+GMExtension.h
+28
-0
UIImage+GMExtension.m
GMAI/Classes/FaceAITool/UIImage+GMExtension.m
+0
-0
UIView+GMExtension.h
GMAI/Classes/FaceAITool/UIView+GMExtension.h
+36
-0
UIView+GMExtension.m
GMAI/Classes/FaceAITool/UIView+GMExtension.m
+128
-0
FaceGuideView.swift
GMAI/Classes/Util/FaceGuideView.swift
+100
-0
NSMutableAttributedString+Attachment.h
GMAI/Classes/Util/NSMutableAttributedString+Attachment.h
+33
-0
NSMutableAttributedString+Attachment.m
GMAI/Classes/Util/NSMutableAttributedString+Attachment.m
+64
-0
UIView+Gradient.h
GMAI/Classes/Util/UIView+Gradient.h
+29
-0
UIView+Gradient.m
GMAI/Classes/Util/UIView+Gradient.m
+107
-0
No files found.
GMAI/Classes/FaceAITool/NSString+jsonData.h
0 → 100644
View file @
e206ca72
//
// NSString+jsonData.h
// Gengmei
//
// Created by lizhen on 2018/11/16.
// Copyright © 2018 更美互动信息科技有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface
NSString
(
jsonData
)
/**
字符串转字典
*/
-
(
NSDictionary
*
)
dictionaryWithJsonString
;
+
(
id
)
jsonToObject
:(
NSString
*
)
json
;
/**
未知类型(仅限字典/数组/字符串)
@param object 字典/数组/字符串
@return 字符串
*/
+
(
NSString
*
)
jsonStringWithObject
:(
id
)
object
;
/**
字典类型转JSON
@param dictionary 字典数据
@return 返回字符串
*/
+
(
NSString
*
)
jsonStringWithDictionary
:(
NSDictionary
*
)
dictionary
;
/**
数组类型转JSON
@param array 数组类型
@return 返回字符串
*/
+
(
NSString
*
)
jsonStringWithArray
:(
NSArray
*
)
array
;
/**
字符串类型转JSON
@param string 字符串类型
@return 返回字符串
*/
+
(
NSString
*
)
jsonStringWithString
:(
NSString
*
)
string
;
@end
NS_ASSUME_NONNULL_END
GMAI/Classes/FaceAITool/NSString+jsonData.m
0 → 100644
View file @
e206ca72
//
// NSString+jsonData.m
// Gengmei
//
// Created by lizhen on 2018/11/16.
// Copyright © 2018 更美互动信息科技有限公司. All rights reserved.
//
#import "NSString+jsonData.h"
@implementation
NSString
(
jsonData
)
/**
字符串转字典
*/
-
(
NSDictionary
*
)
dictionaryWithJsonString
{
if
(
self
==
nil
)
{
return
nil
;
}
NSData
*
jsonData
=
[
self
dataUsingEncoding
:
NSUTF8StringEncoding
];
NSError
*
err
;
NSDictionary
*
dic
=
[
NSJSONSerialization
JSONObjectWithData
:
jsonData
options
:
NSJSONReadingMutableContainers
error
:&
err
];
if
(
err
)
{
NSLog
(
@"json解析失败:%@"
,
err
);
return
nil
;
}
return
dic
;
}
+
(
id
)
jsonToObject
:
(
NSString
*
)
json
{
//string转data
NSData
*
jsonData
=
[
json
dataUsingEncoding
:
NSUTF8StringEncoding
];
//json解析
id
obj
=
[
NSJSONSerialization
JSONObjectWithData
:
jsonData
options
:
NSJSONReadingMutableContainers
error
:
nil
];
return
obj
;
}
/**
未知类型(仅限字典/数组/字符串)
@param object 字典/数组/字符串
@return 字符串
*/
+
(
NSString
*
)
jsonStringWithObject
:
(
id
)
object
{
NSString
*
value
=
nil
;
if
(
!
object
)
{
return
value
;
}
if
([
object
isKindOfClass
:[
NSString
class
]])
{
value
=
[
NSString
jsonStringWithString
:
object
];
}
else
if
([
object
isKindOfClass
:[
NSDictionary
class
]]){
value
=
[
NSString
jsonStringWithDictionary
:
object
];
}
else
if
([
object
isKindOfClass
:[
NSArray
class
]]){
value
=
[
NSString
jsonStringWithArray
:
object
];
}
return
value
;
}
/**
字符串类型转JSON
@param string 字符串类型
@return 返回字符串
*/
+
(
NSString
*
)
jsonStringWithString
:
(
NSString
*
)
string
{
return
[
NSString
stringWithFormat
:
@"%@"
,
[[
string
stringByReplacingOccurrencesOfString
:
@"
\n
"
withString
:
@"
\\
n"
]
stringByReplacingOccurrencesOfString
:
@"
\"
"
withString
:
@"
\\\"
"
]
];
}
/**
数组类型转JSON
@param array 数组类型
@return 返回字符串
*/
+
(
NSString
*
)
jsonStringWithArray
:
(
NSArray
*
)
array
{
NSMutableString
*
reString
=
[
NSMutableString
string
];
[
reString
appendString
:
@"["
];
NSMutableArray
*
values
=
[
NSMutableArray
array
];
for
(
id
valueObj
in
array
)
{
NSString
*
value
=
[
NSString
jsonStringWithObject
:
valueObj
];
if
(
value
)
{
[
values
addObject
:[
NSString
stringWithFormat
:
@"%@"
,
value
]];
}
}
[
reString
appendFormat
:
@"%@"
,[
values
componentsJoinedByString
:
@","
]];
[
reString
appendString
:
@"]"
];
return
reString
;
}
/**
字典类型转JSON
@param dictionary 字典数据
@return 返回字符串
*/
+
(
NSString
*
)
jsonStringWithDictionary
:
(
NSDictionary
*
)
dictionary
{
NSError
*
parseError
=
nil
;
NSData
*
jsonData
=
[
NSJSONSerialization
dataWithJSONObject
:
dictionary
options
:
NSJSONWritingPrettyPrinted
error
:&
parseError
];
return
[[
NSString
alloc
]
initWithData
:
jsonData
encoding
:
NSUTF8StringEncoding
];
}
@end
GMAI/Classes/FaceAITool/UIImage+GMExtension.h
0 → 100644
View file @
e206ca72
//
// UIImage+GMExtension.h
// Gengmei
//
// Created by Q14 on 2018/9/28.
// Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface
UIImage
(
GMExtension
)
+
(
UIImage
*
)
animatedGIFWithData
:(
NSData
*
)
data
;
-
(
UIImage
*
)
animatedImageByScalingAndCroppingToSize
:(
CGSize
)
size
;
-
(
UIImage
*
)
normalizedImage
;
-
(
UIImage
*
)
clipImage
:(
CGFloat
)
scale
;
-
(
UIImage
*
)
scaleImagetoScale
:(
float
)
scaleSize
;
-
(
UIImage
*
)
clipNormalizedImage
:(
CGFloat
)
scale
;
-
(
UIImage
*
)
fullNormalizedImage
;
-
(
UIImage
*
)
clipLeftOrRightImage
:(
CGFloat
)
scale
;
-
(
UIImage
*
)
rotationImage
:(
UIImageOrientation
)
orient
;
-
(
UIImage
*
)
resizableImage
;
-
(
UIImage
*
)
drawRoundedRectImage
:(
CGFloat
)
cornerRadius
width
:(
CGFloat
)
width
height
:(
CGFloat
)
height
;
-
(
UIImage
*
)
drawCircleImage
;
@end
NS_ASSUME_NONNULL_END
GMAI/Classes/FaceAITool/UIImage+GMExtension.m
0 → 100644
View file @
e206ca72
This diff is collapsed.
Click to expand it.
GMAI/Classes/FaceAITool/UIView+GMExtension.h
0 → 100644
View file @
e206ca72
//
// UIView+GMExtension.h
// Gengmei
//
// Created by Q14 on 2018/9/28.
// Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@class
GMPhotoManager
;
@interface
UIView
(
GMExtension
)
@property
(
assign
,
nonatomic
)
CGFloat
gm_x
;
@property
(
assign
,
nonatomic
)
CGFloat
gm_y
;
@property
(
assign
,
nonatomic
)
CGFloat
gm_w
;
@property
(
assign
,
nonatomic
)
CGFloat
gm_h
;
@property
(
assign
,
nonatomic
)
CGSize
gm_size
;
@property
(
assign
,
nonatomic
)
CGPoint
gm_origin
;
/**
获取当前视图的控制器
@return 控制器
*/
//- (UIViewController *)viewController;
//
//- (void)showImageHUDText:(NSString *)text;
//- (void)showLoadingHUDText:(NSString *)text;
//- (void)handleLoading;
//
///* <HXAlbumListViewControllerDelegate> */
//- (void)gm_presentAlbumListViewControllerWithManager:(GMPhotoManager *)manager delegate:(id)delegate;
//
///* <HXCustomCameraViewControllerDelegate> */
//- (void)gm_presentCustomCameraViewControllerWithManager:(GMPhotoManager *)manager delegate:(id)delegate;
@end
GMAI/Classes/FaceAITool/UIView+GMExtension.m
0 → 100644
View file @
e206ca72
//
// UIView+GMExtension.m
// Gengmei
//
// Created by Q14 on 2018/9/28.
// Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//
#import "UIView+GMExtension.h"
//#import "GMAlbumListViewController.h"
//#import "GMPhotoTools.h"
@import
GMKit
;
@implementation
UIView
(
GMExtension
)
-
(
void
)
setGm_x
:(
CGFloat
)
gm_x
{
CGRect
frame
=
self
.
frame
;
frame
.
origin
.
x
=
gm_x
;
self
.
frame
=
frame
;
}
-
(
CGFloat
)
gm_x
{
return
self
.
frame
.
origin
.
x
;
}
-
(
void
)
setGm_y
:
(
CGFloat
)
gm_y
{
CGRect
frame
=
self
.
frame
;
frame
.
origin
.
y
=
gm_y
;
self
.
frame
=
frame
;
}
-
(
CGFloat
)
gm_y
{
return
self
.
frame
.
origin
.
y
;
}
-
(
void
)
setGm_w
:
(
CGFloat
)
gm_w
{
CGRect
frame
=
self
.
frame
;
frame
.
size
.
width
=
gm_w
;
self
.
frame
=
frame
;
}
-
(
CGFloat
)
gm_w
{
return
self
.
frame
.
size
.
width
;
}
-
(
void
)
setGm_h
:
(
CGFloat
)
gm_h
{
CGRect
frame
=
self
.
frame
;
frame
.
size
.
height
=
gm_h
;
self
.
frame
=
frame
;
}
-
(
CGFloat
)
gm_h
{
return
self
.
frame
.
size
.
height
;
}
-
(
void
)
setGm_size
:
(
CGSize
)
gm_size
{
CGRect
frame
=
self
.
frame
;
frame
.
size
=
gm_size
;
self
.
frame
=
frame
;
}
-
(
CGSize
)
gm_size
{
return
self
.
frame
.
size
;
}
-
(
void
)
setGm_origin
:
(
CGPoint
)
gm_origin
{
CGRect
frame
=
self
.
frame
;
frame
.
origin
=
gm_origin
;
self
.
frame
=
frame
;
}
-
(
CGPoint
)
gm_origin
{
return
self
.
frame
.
origin
;
}
/**
获取当前视图的控制器
@return 控制器
*/
-
(
UIViewController
*
)
viewController
{
for
(
UIView
*
next
=
[
self
superview
];
next
;
next
=
next
.
superview
)
{
UIResponder
*
nextResponder
=
[
next
nextResponder
];
if
([
nextResponder
isKindOfClass
:[
UINavigationController
class
]]
||
[
nextResponder
isKindOfClass
:[
UIViewController
class
]])
{
return
(
UIViewController
*
)
nextResponder
;
}
}
return
nil
;
}
-
(
void
)
handleLoading
{
[
UIView
cancelPreviousPerformRequestsWithTarget
:
self
];
for
(
UIView
*
view
in
self
.
subviews
)
{
if
(
view
.
tag
==
10086
)
{
[
UIView
animateWithDuration
:
0
.
2
f
animations
:
^
{
view
.
alpha
=
0
;
}
completion
:^
(
BOOL
finished
)
{
[
view
removeFromSuperview
];
}];
}
}
}
-
(
void
)
handleGraceTimer
{
[
UIView
cancelPreviousPerformRequestsWithTarget
:
self
];
for
(
UIView
*
view
in
self
.
subviews
)
{
if
(
view
.
tag
==
1008611
)
{
[
UIView
animateWithDuration
:
0
.
2
f
animations
:
^
{
view
.
alpha
=
0
;
}
completion
:^
(
BOOL
finished
)
{
[
view
removeFromSuperview
];
}];
}
}
}
@end
GMAI/Classes/Util/FaceGuideView.swift
0 → 100644
View file @
e206ca72
//
// FaceGuideView.swift
// Pods
//
// Created by licong on 2017/3/15.
//
//
import
UIKit
import
GMBaseSwift
import
GMKit
import
GMCache
protocol
ShowGuideProtocol
{
func
showShotGuide
()
->
FaceGuideView
func
showUploadGuide
()
->
FaceGuideView
func
showAnalyzeResultGuide
()
->
FaceGuideView
}
extension
ShowGuideProtocol
where
Self
:
GMBaseController
{
func
showShotGuide
()
->
FaceGuideView
{
let
guide
=
FaceGuideView
(
frame
:
view
.
bounds
)
view
.
addSubview
(
guide
)
guide
.
show
([
"faceInitGuide2"
])
GMCache
.
storeObject
(
atDocumentPathWithkey
:
FaceGuideView
.
cacheKey
,
object
:
FaceGuideView
.
cacheKey
!
as
NSCoding
)
self
.
navigationBar
.
isHidden
=
true
return
guide
}
func
showUploadGuide
()
->
FaceGuideView
{
let
guide
=
FaceGuideView
(
frame
:
view
.
bounds
)
view
.
addSubview
(
guide
)
self
.
navigationBar
.
isHidden
=
true
guide
.
show
([
"faceInitGuide3"
])
GMCache
.
storeObject
(
atDocumentPathWithkey
:
FaceGuideView
.
cacheKey
,
object
:
FaceGuideView
.
cacheKey
!
as
NSCoding
)
return
guide
}
func
showAnalyzeResultGuide
()
->
FaceGuideView
{
let
guide
=
FaceGuideView
(
frame
:
view
.
bounds
)
guide
.
delegate
=
self
as?
FaceGuideViewDelegate
view
.
addSubview
(
guide
)
guide
.
show
([
"faceInitGuide4"
])
self
.
navigationBar
.
isHidden
=
true
GMCache
.
storeObject
(
atDocumentPathWithkey
:
FaceGuideView
.
cacheKey
,
object
:
FaceGuideView
.
cacheKey
!
as
NSCoding
)
return
guide
}
}
@objc
protocol
FaceGuideViewDelegate
:
class
{
@objc
optional
func
faceGuideDidDismiss
()
}
open
class
FaceGuideView
:
GMView
{
weak
var
delegate
:
FaceGuideViewDelegate
?
fileprivate
static
var
cacheKey
:
String
!
//以设备来区分显示到弹不弹出引导,返回为ture表示应该弹guideView
static
func
shouldShow
(
_
deviceKey
:
String
)
->
Bool
{
cacheKey
=
deviceKey
let
obj
=
GMCache
.
fetchObject
(
atDocumentPathWithkey
:
deviceKey
)
let
exsit
=
(
obj
!=
nil
)
return
!
exsit
}
@objc
func
tapImage
()
{
if
let
view
=
self
.
subviews
.
last
{
view
.
removeFromSuperview
()
if
self
.
subviews
.
count
==
0
{
removeFromSuperview
()
#warning("TODO")
// if let controller = AppDelegate.visibleController as? GMBaseController {
// controller.navigationBar.isHidden = false
// }
delegate
?
.
faceGuideDidDismiss
?()
}
}
}
func
show
(
_
imageNames
:
[
String
])
{
for
name
in
imageNames
.
reversed
()
{
let
image
=
UIImage
(
named
:
name
)
let
imageView
=
UIImageView
(
image
:
image
)
imageView
.
frame
=
bounds
addSubview
(
imageView
)
if
#available(iOS 11, *)
{
imageView
.
contentMode
=
.
scaleAspectFit
}
imageView
.
isUserInteractionEnabled
=
true
let
tap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
#selector(
tapImage
)
)
imageView
.
addGestureRecognizer
(
tap
)
}
if
#available(iOS 11, *)
{
self
.
backgroundColor
=
UIColor
.
white
}
}
}
GMAI/Classes/Util/NSMutableAttributedString+Attachment.h
0 → 100644
View file @
e206ca72
//
// NSMutableAttributedString+Attachment.h
// Gengmei
//
// Created by wangyang on 2018/8/7.
// Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface
NSMutableAttributedString
(
Attachment
)
/**
需求:http://wiki.wanmeizhensuo.com/pages/viewpage.action?pageId=9767058#space-menu-link-content
一些卡片标题有置顶标识。
*/
-
(
void
)
addFeedIsTopAttachment
;
// 更美AI结果页加载时,弹出提示框,需要添加图片 Attachment方法封装。
-
(
void
)
addAIPopViewAttachment
;
/**
http://wiki.wanmeizhensuo.com/pages/viewpage.action?pageId=11609153
*/
-
(
void
)
addDiaryMatchAttachment
;
/**
标题前方添加标识(默认为拼团)
*/
-
(
NSAttributedString
*
)
addGroupBuyIsFrontAttachment
:(
NSString
*
)
iconName
;
-
(
NSAttributedString
*
)
addGroupBuyIsFrontAttachment
:(
NSString
*
)
iconName
attachmentBounds
:(
CGRect
)
attachmentBounds
;
@end
GMAI/Classes/Util/NSMutableAttributedString+Attachment.m
0 → 100644
View file @
e206ca72
//
// NSMutableAttributedString+Attachment.m
// Gengmei
//
// Created by wangyang on 2018/8/7.
// Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//
#import "NSMutableAttributedString+Attachment.h"
@import
GMFoundation
;
@implementation
NSMutableAttributedString
(
Attachment
)
-
(
void
)
addFeedIsTopAttachment
{
NSTextAttachment
*
textAttachment
=
[[
NSTextAttachment
alloc
]
init
];
textAttachment
.
image
=
[
UIImage
imageNamed
:
@"feed_is_top"
];
textAttachment
.
bounds
=
CGRectMake
(
0
,
-
1
,
13
,
13
);
// 微调图片位置
NSAttributedString
*
imageAttachment
=
[
NSAttributedString
attributedStringWithAttachment
:
textAttachment
];
// 给最后一个字符尾部添加字符水平间距,以符合设计要求:箭头与文字的间距为8个点
[
self
addAttribute
:
NSKernAttributeName
value
:
@
(
8
)
range
:
NSMakeRange
(
self
.
string
.
length
-
1
,
1
)];
[
self
insertAttributedString
:
imageAttachment
atIndex
:
self
.
string
.
length
];
}
-
(
void
)
addDiaryMatchAttachment
{
NSTextAttachment
*
textAttachment
=
[[
NSTextAttachment
alloc
]
init
];
textAttachment
.
image
=
[
UIImage
imageNamed
:
@"diary_match"
];
//diary_match//feed_is_top
textAttachment
.
bounds
=
CGRectMake
(
0
,
-
2
,
31
,
16
);
// 微调图片位置
NSAttributedString
*
imageAttachment
=
[
NSAttributedString
attributedStringWithAttachment
:
textAttachment
];
// 给最后一个字符尾部添加字符水平间距,以符合设计要求:箭头与文字的间距为8个点
[
self
addAttribute
:
NSKernAttributeName
value
:
@
(
8
)
range
:
NSMakeRange
(
self
.
string
.
length
-
1
,
1
)];
[
self
insertAttributedString
:
imageAttachment
atIndex
:
self
.
string
.
length
];
}
-
(
NSAttributedString
*
)
addGroupBuyIsFrontAttachment
:
(
NSString
*
)
iconName
{
[
self
addGroupBuyIsFrontAttachment
:
iconName
attachmentBounds
:
CGRectMake
(
0
,
-
1
,
25
,
13
)];
// [self addAttribute:NSKernAttributeName value:@(20) range:NSMakeRange(0, 1)];
return
self
;
}
-
(
void
)
addAIPopViewAttachment
{
NSTextAttachment
*
textAttachment
=
[[
NSTextAttachment
alloc
]
init
];
textAttachment
.
image
=
[
UIImage
imageNamed
:
@"face_skin_pop_loadingIcon"
];
textAttachment
.
bounds
=
CGRectMake
(
0
,
-
4
,
66
,
20
);
// 微调图片位置
NSAttributedString
*
imageAttachment
=
[
NSAttributedString
attributedStringWithAttachment
:
textAttachment
];
[
self
insertAttributedString
:
imageAttachment
atIndex
:
0
];
}
-
(
NSAttributedString
*
)
addGroupBuyIsFrontAttachment
:
(
NSString
*
)
iconName
attachmentBounds
:
(
CGRect
)
attachmentBounds
{
NSMutableAttributedString
*
textAttrStr
=
[[
NSMutableAttributedString
alloc
]
init
];
NSTextAttachment
*
textAttachment
=
[[
NSTextAttachment
alloc
]
init
];
textAttachment
.
image
=
[
UIImage
imageNamed
:
iconName
.
isNonEmpty
?
iconName
:
@"groupBuy_icon"
];
textAttachment
.
bounds
=
CGRectMake
(
attachmentBounds
.
origin
.
x
,
attachmentBounds
.
origin
.
y
,
attachmentBounds
.
size
.
width
,
attachmentBounds
.
size
.
height
);
// 微调图片位置
NSAttributedString
*
imageAttachment
=
[
NSAttributedString
attributedStringWithAttachment
:
textAttachment
];
[
textAttrStr
appendAttributedString
:
imageAttachment
];
//标签后添加空格
[
textAttrStr
appendAttributedString
:[[
NSAttributedString
alloc
]
initWithString
:
@" "
]];
// 给最后一个字符尾部添加字符水平间距,以符合设计要求:箭头与文字的间距为8个点
[
self
insertAttributedString
:
textAttrStr
atIndex
:
0
];
return
self
;
}
@end
GMAI/Classes/Util/UIView+Gradient.h
0 → 100644
View file @
e206ca72
//
// UIView+Gradient.h
// Gengmei
//
// Created by Terminator on 2018/8/15.
// Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface
UIView
(
Gradient
)
@property
(
nullable
,
copy
)
NSArray
*
colors
;
@property
(
nullable
,
copy
)
NSArray
<
NSNumber
*>
*
locations
;
@property
CGPoint
startPoint
;
@property
CGPoint
endPoint
;
+
(
UIView
*
_Nullable
)
gradientViewWithColors
:(
NSArray
<
UIColor
*>
*
_Nullable
)
colors
locations
:(
NSArray
<
NSNumber
*>
*
_Nullable
)
locations
startPoint
:(
CGPoint
)
startPoint
endPoint
:(
CGPoint
)
endPoint
;
-
(
void
)
setGradientBackgroundWithColors
:(
NSArray
<
UIColor
*>
*
_Nullable
)
colors
locations
:(
NSArray
<
NSNumber
*>
*
_Nullable
)
locations
startPoint
:(
CGPoint
)
startPoint
endPoint
:(
CGPoint
)
endPoint
;
/**
从一个颜色变化到另一个颜色
@param beginColor 开始颜色
@param endColor 结束颜色
@param percent 百分比
*/
-
(
void
)
getColorWithColor
:(
UIColor
*
_Nullable
)
beginColor
endColor
:(
UIColor
*
_Nullable
)
endColor
percent
:(
double
)
percent
;
@end
GMAI/Classes/Util/UIView+Gradient.m
0 → 100644
View file @
e206ca72
//
// UIView+Gradient.m
// Gengmei
//
// Created by Terminator on 2018/8/15.
// Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//
#import "UIView+Gradient.h"
#import <objc/runtime.h>
@implementation
UIView
(
Gradient
)
+
(
Class
)
layerClass
{
return
[
CAGradientLayer
class
];
}
+
(
UIView
*
)
gradientViewWithColors
:
(
NSArray
<
UIColor
*>
*
)
colors
locations
:
(
NSArray
<
NSNumber
*>
*
)
locations
startPoint
:
(
CGPoint
)
startPoint
endPoint
:
(
CGPoint
)
endPoint
{
UIView
*
view
=
[[
self
alloc
]
init
];
[
view
setGradientBackgroundWithColors
:
colors
locations
:
locations
startPoint
:
startPoint
endPoint
:
endPoint
];
return
view
;
}
-
(
void
)
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
.
colors
=
[
colorsM
copy
];
self
.
locations
=
locations
;
self
.
startPoint
=
startPoint
;
self
.
endPoint
=
endPoint
;
}
-
(
NSArray
*
)
getRGBDictionaryByColor
:
(
UIColor
*
)
originColor
{
CGFloat
r
=
0
,
g
=
0
,
b
=
0
,
a
=
0
;
if
([
self
respondsToSelector
:
@selector
(
getRed
:
green
:
blue
:
alpha
:
)])
{
[
originColor
getRed
:
&
r
green
:
&
g
blue
:&
b
alpha
:&
a
];
}
else
{
const
CGFloat
*
components
=
CGColorGetComponents
(
originColor
.
CGColor
);
r
=
components
[
0
];
g
=
components
[
1
];
b
=
components
[
2
];
a
=
components
[
3
];
}
return
@[
@
(
r
),
@
(
g
),
@
(
b
)];
}
-
(
NSArray
*
)
transColorBeginColor
:
(
UIColor
*
)
beginColor
andEndColor
:
(
UIColor
*
)
endColor
{
NSArray
<
NSNumber
*>
*
beginColorArr
=
[
self
getRGBDictionaryByColor
:
beginColor
];
NSArray
<
NSNumber
*>
*
endColorArr
=
[
self
getRGBDictionaryByColor
:
endColor
];
return
@[
@
([
endColorArr
[
0
]
doubleValue
]
-
[
beginColorArr
[
0
]
doubleValue
]),
@
([
endColorArr
[
1
]
doubleValue
]
-
[
beginColorArr
[
1
]
doubleValue
]),
@
([
endColorArr
[
2
]
doubleValue
]
-
[
beginColorArr
[
2
]
doubleValue
])];
}
-
(
void
)
getColorWithColor
:
(
UIColor
*
)
beginColor
endColor
:
(
UIColor
*
)
endColor
percent
:
(
double
)
percent
{
NSArray
*
colorArray
=
[
self
transColorBeginColor
:
beginColor
andEndColor
:
endColor
];
NSArray
*
beginColorArr
=
[
self
getRGBDictionaryByColor
:
beginColor
];
double
red
=
[
beginColorArr
[
0
]
doubleValue
]
+
percent
*
[
colorArray
[
0
]
doubleValue
];
double
green
=
[
beginColorArr
[
1
]
doubleValue
]
+
percent
*
[
colorArray
[
1
]
doubleValue
];
double
blue
=
[
beginColorArr
[
2
]
doubleValue
]
+
percent
*
[
colorArray
[
2
]
doubleValue
];
self
.
backgroundColor
=
[
UIColor
colorWithRed
:
red
green
:
green
blue
:
blue
alpha
:
1
];
}
#pragma mark - Getter&Setter
-
(
NSArray
*
)
colors
{
return
objc_getAssociatedObject
(
self
,
_cmd
);
}
-
(
void
)
setColors
:
(
NSArray
*
)
colors
{
objc_setAssociatedObject
(
self
,
@selector
(
colors
),
colors
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[(
CAGradientLayer
*
)
self
.
layer
setColors
:
self
.
colors
];
}
}
-
(
NSArray
<
NSNumber
*>
*
)
locations
{
return
objc_getAssociatedObject
(
self
,
_cmd
);
}
-
(
void
)
setLocations
:
(
NSArray
<
NSNumber
*>
*
)
locations
{
objc_setAssociatedObject
(
self
,
@selector
(
locations
),
locations
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[((
CAGradientLayer
*
)
self
.
layer
)
setLocations
:
self
.
locations
];
}
}
-
(
CGPoint
)
startPoint
{
return
[
objc_getAssociatedObject
(
self
,
_cmd
)
CGPointValue
];
}
-
(
void
)
setStartPoint
:
(
CGPoint
)
startPoint
{
objc_setAssociatedObject
(
self
,
@selector
(
startPoint
),
[
NSValue
valueWithCGPoint
:
startPoint
],
OBJC_ASSOCIATION_RETAIN_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[((
CAGradientLayer
*
)
self
.
layer
)
setStartPoint
:
self
.
startPoint
];
}
}
-
(
CGPoint
)
endPoint
{
return
[
objc_getAssociatedObject
(
self
,
_cmd
)
CGPointValue
];
}
-
(
void
)
setEndPoint
:
(
CGPoint
)
endPoint
{
objc_setAssociatedObject
(
self
,
@selector
(
endPoint
),
[
NSValue
valueWithCGPoint
:
endPoint
],
OBJC_ASSOCIATION_RETAIN_NONATOMIC
);
if
([
self
.
layer
isKindOfClass
:[
CAGradientLayer
class
]])
{
[((
CAGradientLayer
*
)
self
.
layer
)
setEndPoint
:
self
.
endPoint
];
}
}
@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