高级渐变?
UIView 的每个角都有颜色,是否可能有渐变?
Is it possibly to have a gradient where there's a colour in each corner of a UIView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
UIView 的每个角都有颜色,是否可能有渐变?
Is it possibly to have a gradient where there's a colour in each corner of a UIView?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
没有内置的方法可以做到这一点,也没有简单的方法可以通过 Quartz 来做到这一点。不过,您可以通过 Quartz 来实现这一点,方法是创建 4 个不同方向的不同 2-D 渐变,并用垂直运行的黑白渐变遮盖每个渐变。
假设您的颜色定义为:tlColor、trColor、blColor、brColor(用于左上角、右上角等)。
您可能想先在 Acorn 或 Photoshop 中尝试一下...因此,在将其转换为代码之前,您应该清楚所涉及的内容。然后 Quartz 参考 @lxt 指出有关于渐变的部分(CGGradientRef 就足够了,不要尝试使用阴影),以及关于图像蒙版的单独部分。
There's no built-in way to do this, and no simple way to do this via Quartz either. However, you can do it via Quartz by creating 4 different 2-D gradients going in different directions, and masking each one with a black-white gradient running perpendicular.
Assuming your colors are defined as: tlColor, trColor, blColor, brColor (for top-left, top-right, etc.).
You might want to try this in Acorn or Photoshop first... so it's clear what's involved before you translate it into code. Then the Quartz reference @lxt pointed you to has sections on gradients (CGGradientRef is sufficient, don't try to use shadings), and a separate section on image masks.
我有 2 个渐变对角线放置。使用覆盖混合
要更改颜色,您应该有 4 个 UIColors 作为视图上的成员,并相应地更改此片段。
I have 2 gradients placed diagonal. With overlay-blending
To change the color you should have 4 UIColors as members on the view and change this fragment accordingly.
这是一个可行的解决方案。
绘制两种颜色渐变时,一个垂直渐变位图蒙版既可以按原样使用,也可以镜像使用。
FourTimesRGBA分量是四个角颜色UL、UR、LL、LR的R、G、B、A分量,即ULR、ULG、ULB、ULA、URR等。
Here is a working solution.
One vertical gradient bitmap mask used both as is and mirrored when drawing two color gradients.
FourTimesRGBAcomponents is the R,G,B,A components of the four corner colors UL, UR, LL and LR, i.e. ULR, ULG, ULB, ULA, URR etc.
为了比卡尔更有帮助,答案是“是”,但如何实现它取决于您想要使用的技术。 Quartz 渐变系统的描述如下:
http: //developer.apple.com/library/mac/#documentation/graphicsimaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html
...但是OpenGL是另一种可能性。这取决于您的应用程序。
To be a little more helpful than Carl, the answer is 'yes', but how you implement it would depend on the tech you wanted to use. The Quartz gradient system is described here:
http://developer.apple.com/library/mac/#documentation/graphicsimaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html
...but OpenGL is another possibility. It would depend on your application.