How to change CAGradientLayer color points?

≡放荡痞女 提交于 2019-11-28 19:11:18
rob mayoff

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!