我的客戶想要背景使用此漸變效果查看 背景漸變:rgb(118,118,118)| #ffffff | RGB(198198197)線性左至右 我已經試過這種方式,但它是在垂直方向上發生的事情,我希望它在水平方式背景漸變:在目標中線性從左到右C
UIColor *leftColor = [UIColor colorWithRed:118.0/255.0 green:118.0/255.0 blue:118.0/255.0 alpha:1.0];
UIColor *middleColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0];
UIColor *rightColor = [UIColor colorWithRed:198.0/255.0 green:198.0/255.0 blue:197.0/255.0 alpha:1.0];
// Create the gradient
CAGradientLayer *theViewGradient = [CAGradientLayer layer];
theViewGradient.colors = [NSArray arrayWithObjects: (id)leftColor.CGColor, (id)middleColor.CGColor,(id)rightColor.CGColor, nil];
theViewGradient.frame = self.view.bounds;
//Add gradient to view
[self.view.layer insertSublayer:theViewGradient atIndex:0];
[梯度setStartPoint:CGPointMake(0,0 )]; [梯度對setEndpoint:CGPointMake(0,1)]; 加載開始點和結束點 –
@ harshal帷幔它幫助 theViewGradient.startPoint = CGPointMake(0.0,0.0); theViewGradient.endPoint = CGPointMake(1.0,0.0); 感謝 –