ios - 在 Eureka TextRow 中更改 UIImageView 的高度

标签 ios swift swift3 uiimageview eureka-forms

Eureka 使用 Swift 以寄存器形式处理验证码行。 我插入了一个 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)
    }

screen shot

最佳答案

尝试使用预期高度调整 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
        }

关于ios - 在 Eureka TextRow 中更改 UIImageView 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43932333/

相关文章:

Swift错误编译错误: default label can only appear in switch statement

ios - 设置字体需要覆盖 sizeToFit() Swift 的大小

ios - 从 TableView 单元格到另一个 View Controller 的 Segue 转换仅在任意时间有效 - 为什么?

ios - 来自 web 服务的更新表中的 viewWillAppear 延迟

ios - 检测 UIImagePicker OverlayView 方向

ios - 用于 MKAnnotationView 按钮点击的自定义 View Xib

c++ - 如何在IOS中使用fstream读取XML文件

ios - 如何将字典的内容转储到 UITextView 或 UILabel 中?

ios - Swift,谷歌地图适用于所有标记

ios - 仍然收到错误 "No such module ' SwiftyDropbox'”