iOS White to Transparent Gradient Layer is Gray

前端 未结 7 1213
清歌不尽
清歌不尽 2021-02-01 11:53

I have a CAGradientLayer inserted to the bottom of this small detail view that pops up at the bottom of the app. As you can see, I\'ve set the colors from white to clear, but th

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 12:10

    The answers above such as:

    UIColor.white.withAlphaComponent(0).cgColor
    

    and

    UIColor(white: 1.0, alpha: 0.0).cgColor
    

    should work in terms of getting a portion of your gradient to be clear (rather than the gray that OP is referring to). However, if you're still seeing a transparent white when you should be seeing a clear color, make sure the backgroundColor of the view to which you're applying the gradient is clear as well.

    By default, that view's background color will likely be white (or a dark color if the device is in dark mode), so when you apply the gradient, the clear portion of it will be "blocked" by the view's backgroundColor itself. Set that to clear and you should be good to go.

提交回复
热议问题