How to change CAGradientLayer color points?

前端 未结 1 1651
感动是毒
感动是毒 2020-12-14 00:32

Right now I\'ve got a GA Gradient layer where I\'ve set the colors but I\'d like to set the color point to (instead of top center, to top left) and the bottom to (instead of

相关标签:
1条回答
  • 2020-12-14 01:26

    The startPoint and endPoint properties of a CAGradientLayer are defined in the “unit coordinate system”. In the unit coordinate system:

    • (0,0) corresponds to the smallest coordinates of the layer's bounds rectangle, which on iOS is its upper-left corner unless the layer has been transformed;
    • (1,1) corresponds to the largest coordinates of the layer's bounds rectangle, which on iOS is its lower-right corner unless the layer has been transformed.

    Thus arranging your gradient the way you want should be this simple:

    gradient.startPoint = CGPoint.zero
    gradient.endPoint = CGPoint(x: 1, y: 1)
    
    0 讨论(0)
提交回复
热议问题