Skip to content

Commit 1230a57

Browse files
authored
Merge pull request #1290 from xixisplit/imageGradient
UIImage+QMUI 分类<qmui_imageWithGradientColors>渐变色方法增加左上至右下,右上至左下的倾斜的渐变色枚举
2 parents fcd97c5 + 7acd386 commit 1230a57

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

QMUIKit/UIKitExtensions/UIImage+QMUI.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ typedef NS_ENUM(NSInteger, QMUIImageResizingMode) {
5252
typedef NS_ENUM(NSInteger, QMUIImageGradientType) {
5353
QMUIImageGradientTypeHorizontal,
5454
QMUIImageGradientTypeVertical,
55+
QMUIImageGradientTypeTopLeftToBottomRight,
56+
QMUIImageGradientTypeTopRightToBottomLeft,
5557
QMUIImageGradientTypeRadial,
5658
};
57-
5859
@interface UIImage (QMUI)
5960

6061
/**
@@ -319,7 +320,7 @@ typedef NS_ENUM(NSInteger, QMUIImageGradientType) {
319320
/**
320321
创建一个渐变图片,支持线性、径向。
321322
@param colors 渐变的颜色,不能为空,数量必须与 locations 数量一致(除非 locations 为 nil)
322-
@param type 渐变的类型,可选为水平、垂直、径向
323+
@param type 渐变的类型,可选为水平、垂直、径向、左上至右下、右上至左下
323324
@param locations 渐变变化的位置,数量必须与 colors 一致,值为 [0.0-1.0] 之间的 CGFloat。如果参数传 nil 则默认为 @[@0, @1]
324325
@param size 图片的尺寸,如果是径向渐变,宽高不相等时会变成椭圆的渐变。
325326
@param cornerRadius 四个角的圆角值的数组,长度必须为4,顺序分别为[左上角、左下角、右下角、右上角]

QMUIKit/UIKitExtensions/UIImage+QMUI.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,15 @@ + (UIImage *)qmui_imageWithGradientColors:(NSArray<UIColor *> *)colors type:(QMU
629629
if (type == QMUIImageGradientTypeHorizontal) {
630630
startPoint = CGPointMake(0, 0);
631631
endPoint = CGPointMake(size.width, 0);
632-
} else {
632+
} else if(type == QMUIImageGradientTypeVertical) {
633633
startPoint = CGPointMake(0, 0);
634634
endPoint = CGPointMake(0, size.height);
635+
}else if (type == QMUIImageGradientTypeTopLeftToBottomRight){
636+
startPoint = CGPointMake(0, 0);
637+
endPoint = CGPointMake(size.width, size.height);
638+
}else if (type == QMUIImageGradientTypeTopRightToBottomLeft){
639+
startPoint = CGPointMake(size.width, 0);
640+
endPoint = CGPointMake(0, size.height);
635641
}
636642
CGContextDrawLinearGradient(contextRef, gradient, startPoint, endPoint, kCGGradientDrawsBeforeStartLocation);
637643
}

0 commit comments

Comments
 (0)