How to make shadow effect in circle view with cornerRadius
litt1e-p opened this issue · 9 comments
@PierrePerrin Hi, does ShadowView support circle view with cornerRadius, I did tried it out. here is my code:
Hi I think tou forget to paste your code.
Normally the Shadow view uses its subview to prepare the shadow.
If you set a rounded subview, you shadow should be sound.
If tou are using a sinple UIView and want a circle shadowView you need to set the shadowPath to nil or override it.
import UIKit
import SnapKit
import ShadowView
class gView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(bgView)
bgView.addSubview(imgView)
bgView.snp.makeConstraints { (m) in
m.centerX.equalTo(self)
m.centerY.equalTo(self.snp.bottom).multipliedBy(1/3.0)
m.width.equalTo(self).multipliedBy(1/2.0)
m.height.equalTo(bgView.snp.width)
}
imgView.snp.makeConstraints { (m) in
m.edges.equalTo(bgView)
}
imgView.layer.cornerRadius = self.frame.size.width / 4.0
imgView.layer.masksToBounds = true
bgView.shadowRadius = 10
bgView.shadowOffset = CGSize(width: 5, height: 5)
bgView.shadowOpacity = 0.5
}
func assign(with img: UIImage) {
bgView.updateShadow()
}
fileprivate lazy var bgView: ShadowView = {
let v = ShadowView(color: .clear)
return v
} ()
fileprivate lazy var imgView: UIImageView = {
let iv = UIImageView(contentMode: UIViewContentMode.scaleAspectFill, image: nil)
return iv
} ()
}
here is my code, and it crashed
I wondering that maybe updateShadow
too early?
Yes if you assign your image before the context is created (when the view is going to be displayed) it won't work.
I should make the context optional in order to prevent the crash.
Sorry, you must set a frame to the shadow view before adding it to your view.
More than that, you never set the image of your imageView.
Is shadow view working in the example ?
Do try to edit the example to make the effect you want ?
Without debugging I won't be able to help you with your problem...
@PierrePerrin sorry about previous bug I made, I fixed it now by set bgView's frame and image. Thanks again