【问题标题】:Swift UIKit how to masksToBounds for image viewSwift UIKit 如何为图像视图遮罩到边界
【发布时间】:2020-12-12 20:37:54
【问题描述】:

我的父视图四面都有圆角,我希望子图像视图的右上角和右下角都有圆角以适合父视图。 Swift documentation 说 masksToBounds 会解决这个问题,但它对我不起作用。从照片中可以看出,照片的右侧没有在右侧倒圆。如果您想查看我的更多代码,请告诉我,谢谢。

这是我的代码:

            bottomViewThumbnailImageView.translatesAutoresizingMaskIntoConstraints = false
            bottomViewThumbnailImageView.clipsToBounds = true
            bottomViewThumbnailImageView.layer.masksToBounds = true

            
            NSLayoutConstraint.activate([
                bottomViewThumbnailImageView.topAnchor.constraint(equalTo: bottomView.topAnchor),
                bottomViewThumbnailImageView.bottomAnchor.constraint(equalTo: bottomView.bottomAnchor),
                bottomViewThumbnailImageView.trailingAnchor.constraint(equalTo: bottomView.trailingAnchor),
                bottomViewThumbnailImageView.heightAnchor.constraint(equalTo: bottomViewThumbnailImageView.widthAnchor),
            ])

【问题讨论】:

    标签: swift uiimage uikit


    【解决方案1】:

    试着为你的细胞提供这个

    layer.masksToBounds = true
    

    【讨论】:

      【解决方案2】:

      应该为 imageView 父级设置该属性,因为它将流向它的子级,将其设置为 imageView 本身没有效果

      parentImg.clipsToBounds = true
      

      【讨论】:

        猜你喜欢
        • 2021-08-28
        • 2013-04-05
        • 1970-01-01
        • 1970-01-01
        • 2022-10-23
        • 2010-12-05
        • 2013-01-11
        • 2017-09-28
        • 2018-05-29
        相关资源
        最近更新 更多