簡體   English   中英

在Eureka TextRow中更改UIImageView的高度

[英]Change height of UIImageView in Eureka TextRow

使用Swift在Eureka上以注冊形式處理驗證碼行。 我插入了一個TextRow並將驗證碼圖像分配給了cell.imageView ,但圖像略高,覆蓋了行線。 如何更改圖像的高度?

嘗試了cell.imageView?.frame ,無法正常工作。

代碼如下。 非常感謝。

<<< TextRow(){ row in
    row.title = ""
    row.tag = "Captcha"
    }.cellSetup { cell, row in
        cell.imageView?.image = UIImage(data:imgData!, scale:1)
        //this line is not working
        cell.imageView?.frame = CGRect(x: 0, y: 0, width: 98, height: 28)
    }

屏幕截圖

嘗試使用預期高度調整imageView的大小

 cell.imageView?.image = self.resizeImage(image:  UIImage(data:imgData!, scale:1), expectedHeight: 28)

    func resizeImage(image: UIImage, expectedHeight: CGFloat) -> UIImage 
       {
            var image = image
            let scale = expectedHeight / image.size.height
            let newWidth = image.size.width * scale
            UIGraphicsBeginImageContext(CGSize(width :newWidth, height : expectedHeight))

            image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: expectedHeight))
            image = UIGraphicsGetImageFromCurrentImageContext()!
            UIGraphicsEndImageContext()

            return image
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM