重叠不同颜色和Alpha的UIViews [英] Overlapping UIViews of Differing Color and Alpha
问题描述
有没有办法将不同的背景颜色和alpha通过重叠2个或更多的 UIViews
来给出另一种颜色的外观?例如,在蓝色的 UIView
之上放置一个红色的 UIView
,使单个洋红色<$ c $在iOS上唯一的视图混合模式,如果所谓的视图源代码模式。
基本上RGB_result = RGB_back *(1 - Alpha_front)+ RGB_front * Alpha_front
因此在蓝色(0,0,1)视图顶部有0.5 alpha的红色(1,0,0)视图将导致深色洋红色(0.5,0,0.5)
如果您需要其他混合模式,请考虑使用CoreGraphics绘图(例如 CGContextSetBlendMode
)
Is there a way to overlap 2 or more UIViews
with differing background colors and alphas to give the appearance of another color? For example place a red UIView
on top of a blue UIView
to give the appearance of a single magenta UIView
.
On iOS the only blending mode for views if the so-called "source over" mode.
Basically RGB_result = RGB_back * (1 - Alpha_front) + RGB_front * Alpha_front
Thus a red (1, 0, 0) view with 0.5 alpha on top of a blue (0, 0, 1) view will result in dark magenta (0.5, 0, 0.5)
If you need some other blending mode, consider drawing with CoreGraphics (e.g. CGContextSetBlendMode
)
这篇关于重叠不同颜色和Alpha的UIViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!