oracle数据库渐变色,layer绘制渐变色

layer绘制渐变色

– (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

NSArray *colors = [NSArray arrayWithObjects:HEXCOLOR(0x769DC5),HEXCOLOR(0x4F5B9B), nil];

[self drawGradientColor:context rect:rect options:kCGGradientDrawsAfterEndLocation colors:colors];

CGContextStrokePath(context);// 描线,即绘制形状

CGContextFillPath(context);// 填充形状内的颜色

}

/**

* 绘制背景色渐变的矩形,p_colors渐变颜色设置,集合中存储UIColor对象(创建Color时一定用三原色来创建)

**/

– (void)drawGradientColor:(CGContextRef)pContext

rect:(CGRect)pClipRect

options:(CGGradientDrawingOptions)pOptions

colors:(NSArray *)pColors {

CGContextSaveGState(pContext);// 保持住现在的context

CGContextClipToRect(pContext, pClipRect);// 截取对应的context

int colorCount = (int)pColors.count;

int numOfComponents = 4;

CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();

CGFloat colorComponents[colorCount * numOfComponents];

for (int i = 0; i < colorCount; i++) {

UIColor *color = pColors[i];

CGColorRef temcolorRef = color.CGColor;

const CGFloat *components = CGColorGetComponents(temcolorRef);

for (int j = 0; j < numOfComponents; ++j) {

colorComponents[i * numOfComponents + j] = components[j];

}

}

CGGradientRef gradient =  CGGradientCreateWithColorComponents(rgb, colorComponents, NULL, colorCount);

CGColorSpaceRelease(rgb);

CGPoint startPoint = pClipRect.origin;

CGPoint endPoint = CGPointMake(CGRectGetMinX(pClipRect), CGRectGetMaxY(pClipRect));

CGContextDrawLinearGradient(pContext, gradient, startPoint, endPoint, pOptions);

CGGradientRelease(gradient);

CGContextRestoreGState(pContext);// 恢复到之前的context

}

//加阴影

_bgView.layer.shadowColor= [UIColorgrayColor].CGColor;//shadowColor阴影颜色

_bgView.layer.shadowOffset=CGSizeMake(2,1);//shadowOffset阴影偏移,x向右偏移4,y向下偏移4,默认(0,

-3),这个跟shadowRadius配合使用

_bgView.layer.shadowOpacity=0.5;//阴影透明度,默认0

_bgView.layer.shadowRadius=3;//阴影半径,默认3

转载自:https://blog.csdn.net/haixialu/article/details/50267701

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值