【问题标题】:Round bottom line of an image view图像视图的圆形底线
【发布时间】:2017-05-21 19:36:25
【问题描述】:

我只希望我的imageView 的底部边框被舍入。我如何以编程方式做到这一点?

感谢您的帮助!

【问题讨论】:

标签: ios swift image layer


【解决方案1】:

您可以通过子类化 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
}
}

结果会是这样的:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多