I have a UIImageView and I wanted to add a black overlay on top of it. What is the best way of doing this without having to override drawRect? I was thinking of adding a CALayer on top of it. But unsure how to get a black CALayer with a .3 alpha.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Did you think about adding a
UIView
with black backgroundColor and 0.3 alpha as a subview to the image view?Something like this?
Thanks to Mick MacCallum
Swift 3 Version
I have used for Swift 2.2
This is similar to MDT's answer except using CALayer properties:
The MDT answer is correct. This is just another way to use a
CAGradientLayer
beside ofUIView
. I think it will make what you want with more graphical options.first you should add
to your
ViewController.m
and any place that you want to add this overlay to yourUIImage
use:I hope this will help you make it