图像视图的圆底线

时间:2017-05-21 19:36:26

标签: ios swift image layer

我只希望将imageView的下边框四舍五入。我该如何以编程方式执行此操作?

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

您可以通过对UIImageView进行子类化来完成此操作:

import UIKit
class CustomImageView: UIImageView {

override public func layoutSubviews() {
    super.layoutSubviews()
    self.roundUpCorners([.bottomLeft, .bottomRight], radius: 30)
}
}
extension UIView {
func roundUpCorners(_ corners: UIRectCorner, radius: CGFloat) {
    let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
    let mask = CAShapeLayer()
    mask.path = path.cgPath
    self.layer.mask = mask
}
}

结果将是这样的:enter image description here