
在0.0处,梯度是水平的(颜色A在顶部,颜色B在下面),旋转360度到值1.0(与值0.0相同 – 或完整旋转).
例如.当x = 0.25时,左边是颜色A,颜色B是右边.在0.5时,颜色A在下面,颜色B在上面,0.75颜色A在右边,颜色B在左边.它从右向左逆时针旋转.
它需要四个参数:frame,colourA,colourB和输入值(0-1).
-(UIVIEw *)gradIEntVIEwWithFrame:(CGRect)frame colourA:(UIcolor *)A colourB:(UIcolor *)B rotation:(float)x {//x is between 0 and 1,eg. from a slIDer,representing 0 - 360 degrees//colour A starts on top,with colour B below//rotations move anti-clockwise//1. create the colour vIEwUIVIEw * colourVIEw = [UIVIEw new];colourVIEw.frame = frame;//2. create the gradIEnt layerCAGradIEntLayer *gradIEnt = [CAGradIEntLayer layer];gradIEnt.frame = colourVIEw.bounds;gradIEnt.colors = [NSArray arrayWithObjects:(ID)[A CGcolor],(ID)[B CGcolor],nil];[colourVIEw.layer insertSublayer:gradIEnt atIndex:0];//3. create coordinatesfloat a = pow(sinf((2*M_PI*((x+0.75)/2))),2);float b = pow(sinf((2*M_PI*((x+0.0)/2))),2);float c = pow(sinf((2*M_PI*((x+0.25)/2))),2);float d = pow(sinf((2*M_PI*((x+0.5)/2))),2);//4. set the gradIEnt direction[gradIEnt setStartPoint:CGPointMake(a,b)];[gradIEnt setEndPoint:CGPointMake(c,d)];return colourVIEw;} 总结 以上是内存溢出为你收集整理的ios – 使用CAGradientLayer定义渐变的角度全部内容,希望文章能够帮你解决ios – 使用CAGradientLayer定义渐变的角度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)