我有一个 UIView,我希望它有阴影和圆角。
问题是 - 阴影需要 masksToBounds = NO
而圆角需要 masksToBounds = YES
。
我找到的解决方案是有一个有阴影的容器,并将我的 UIView 添加为容器的 subview - 并给它圆角。
这行得通。我有阴影和圆角 - 但它不好。 阴影是矩形 View ,我的图像有圆角。
如何为圆角添加阴影?
最佳答案
import UIKit
@IBDesignable
class customButton: UIView {
@IBInspectable var cornerRadius:CGFloat = 0{
didSet{
self.layer.cornerRadius = cornerRadius
}
}
@IBInspectable var borderWidth:CGFloat = 0{
didSet{
self.layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor:UIColor = UIColor.white{
didSet{
self.layer.borderColor = borderColor.cgColor
}
}
}
将其设置为 UIView 的类并放置 maskToBound = true
。然后在检查器中相应地设置值以获得圆形阴影。
关于ios - UIView 阴影和圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24927621/