问题描述
我有一个 UIView
,我想要一个径向渐变,我想知道如何去做?
I have a UIView
which I want to have a radial gradient, and I'm wondering how to go about doing this?
推荐答案
为此,您需要下拉到 Core Graphics 并使用 CGContextDrawRadialGradient.
To do this you need to drop down to Core Graphics and use CGContextDrawRadialGradient.
类似的堆栈溢出问题
如何绘制Core Graphics/iPhone 的渐变线(淡入/淡出)?
其他资源
这里有一个教程,展示了如何在 iOS 上绘制带有渐变的图标:
There's a tutorial showing how to draw icons with gradients on iOS here:
http://redartisan.com/2011/05/13/porting-iconapp-core-graphics
他已将代码放在 Github 上,并附有一个 UIView 子类,该子类展示了使用 Core Graphics 制作渐变的(相当冗长的)方法:
He's put the code on Github, complete with a UIView subclass that shows the (rather longwinded) way of making gradients using Core Graphics:
https://github.com/crafterm/IconApp/blob/master/IconApp/IconView.m
这篇关于如何向 UIView 添加径向渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!