【发布时间】:2019-10-02 09:34:35
【问题描述】:
我想将圆角半径设置为 UITabBar 并设置阴影。它应该看起来像 img1,但它看起来像 img2。
我的代码:
tabBar.barTintColor = .white
tabBar.isTranslucent = false
tabBar.dropShadow(shadowColor: UIColor.lightGray, fillColor: UIColor.white, opacity: 1, offset: CGSize(width: 0, height: 5), radius: 25)
tabBar.layer.masksToBounds = false
tabBar.isTranslucent = true
tabBar.barStyle = .blackOpaque
tabBar.layer.cornerRadius = 13
tabBar.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
和扩展
extension UIView{
func dropShadow(shadowColor: UIColor = UIColor.black,
fillColor: UIColor = UIColor.white,
opacity: Float = 0.2,
offset: CGSize = CGSize(width: 0.0, height: 5.0),
radius: CGFloat = 10) -> CAShapeLayer {
let shadowLayer = CAShapeLayer()
shadowLayer.path = UIBezierPath(roundedRect: self.bounds, cornerRadius: radius).cgPath
shadowLayer.fillColor = fillColor.cgColor
shadowLayer.shadowColor = shadowColor.cgColor
shadowLayer.shadowPath = shadowLayer.path
shadowLayer.shadowOffset = offset
shadowLayer.shadowOpacity = opacity
shadowLayer.shadowRadius = radius
layer.insertSublayer(shadowLayer, at: 0)
return shadowLayer
}
}
【问题讨论】:
-
这里需要先检查设备,再设置rect的边界
-
你有解决第二张图片的方法吗?
标签: swift xcode uitabbarcontroller uitabbar