I've literally tried everything I could but none of them work for a custom UIView
... I just wanted a blank white view with rounded corners and a light drop shadow (with no lighting effect). I can do each of those one by one but the usual clipToBounds
/maskToBounds
conflicts occur.
相关问题
- 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: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Something swifty tested in swift 4
Produces
If you enable it in the Inspector like this:
It will add the User Defined Runtime Attribute, resulting in:
(I added previously the
cornerRadius = 8
):)
After one whole day research of the round corner view with shadow, I'm glad to post my custom uiview class here, hope to end this question:
RoundCornerShadowView.h
RoundCornerShadowView.m
so, NO need to add subview in view or below in target view, just add one layer in current view, and do 3 step to complete it!
take a close look at to the comments in the code, it's helpful to understanding the component!
Swift 3 & IBInspectable solution:
Inspired by Ade's solution
First, create an UIView extension:
Then, simply select your UIView in interface builder setting shadow ON and corner radius, like below:
The result!
You need add
masksToBounds = true
for combined betweencorderRadius
shadowRadius
.Well if you don't want to change your nibs and view hierarchy as suggested David C. this method will do it for you. To add rounded corners and shadow to your UIImageView just use this method, for example:
(!) For performance reasons I don't think it is a good idea to use this code in something like UITableView, since this code changes view hierarchy. So I will suggest to change your nib and add a container view for shadow effect and use Davic C. code.