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
.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Emacs/xterm color annoyance on Linux
This gives a purple view, no problem.
The below method working for me
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
)You could use the alpha property like so:
Note, this is much easier to achieve in a single view by getting the colour you want manually using the RGB creation method of UIColor:
The RGB values are between 0 and 1, note (not the standard 0 -> 255 range that most would normally be specified with). The alpha value denotes the opacity.