用于 CGContext 绘制渐变使用
typedef CF_OPTIONS (uint32_t, CGGradientDrawingOptions) {
kCGGradientDrawsBeforeStartLocation = (1 << 0),
kCGGradientDrawsAfterEndLocation = (1 << 1)
};// 渐变选项
- 颜色组件 梯度初始化
CGColorSpaceRef spaceRef = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {1,0,0,1, 0,1,0,1, 0,0,1,1};
CGFloat locations[] = {0.0, 0.5, 1.0};
CGGradientRef gradeRef = CGGradientCreateWithColorComponents(spaceRef,
components,
locations,
sizeof(locations)/sizeof(locations[0]));
- 颜色数组 梯度初始化
CGColorSpaceRef spaceRef = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = {0.0, 0.5, 1.0};
// 创建 颜色1
CGFloat beginColor[] = {1,0,0,1};
CGColorRef beginColorRef = CGColorCreate(spaceRef, beginColor);
// 创建 颜色2
CGFloat midColor[] = {0,1,0,1};
CGColorRef midColorRef = CGColorCreate(spaceRef, midColor);
// 创建 颜色3
CGFloat endColor[] = {0,0,1,1};
CGColorRef endColorRef = CGColorCreate(spaceRef, endColor);
// 创建颜色数组
CFArrayRef colorArrayRef = CFArrayCreate(kCFAllocatorDefault,
(const void*[]){beginColorRef, midColorRef,endColorRef},
3,
nil);
// 渐变
CGGradientRef gradeRef2 = CGGradientCreateWithColors(spaceRef,
colorArrayRef,
locations);
操作
CG_EXTERN CGGradientRef __nullable CGGradientRetain(
CGGradientRef __nullable gradient)
CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
CG_EXTERN void CGGradientRelease(CGGradientRef __nullable gradient)
CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
1