iosiphoneobjective-cuiviewuiviewanimation

Change Background color of UIView With Multicolor


i want to make my UIView Background color like following image

enter image description here

when i press on button the view's background color will become like above. i was googling to much but not find a way.Can you please help me?


Solution

  • You can do this using CALayer.

    1.Create a CAGradientLayer.

    2.Set the layer's colours property to your rainbow colours.

    3.set startPoint and the layer's endPoint as per your requirement.

    4.Create a CAShapeLayer(for the shape) and set it as the gradient layer's mask.

    Enjoy!!