How to stop an image from stretching within a UIImageView?

前端 未结 10 2384
北恋
北恋 2020-12-23 19:10

I have a UIImageView where I have set the frame size to x = 0, y = 0, width = 404, height = 712. In my project, I need to change the image in

10条回答
  •  [愿得一人]
    2020-12-23 19:37

    still stretch when image is bigger than imageivew

    swift

        let qCodeImage = UIImage(named: "qcode-placeholder.png")!      
        let qCodeImageView = UIImageView(frame: CGRectMake(0, 0, CGRectGetWidth(cardView.frame)-30, CGRectGetWidth(cardView.frame)-30))
        qCodeImageView.image = qCodeImage
        qCodeImageView.clipsToBounds = true
        qCodeImageView.contentMode = UIViewContentMode.ScaleToFill
        qCodeImageView.center = cardView.center
    

提交回复
热议问题