【问题标题】:Change height of UIImageView in Eureka TextRow在 Eureka TextRow 中更改 UIImageView 的高度
【发布时间】:2017-05-12 07:53:34
【问题描述】:

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)
    }

【问题讨论】:

  • 你使用了自动布局吗?
  • @KKRocks 我不确定。单元格中的 imageView 由代码(由 Eureka)定义,而不是在情节提要上。但我想是的。调试器说“[LayoutConstraints] 无法同时满足约束。”尝试更改高度时。
  • 也许你是用scale:1 强制大小,你是否尝试只传递data 参数?
  • @Efren 是的,但scale 部分似乎没有任何影响。删除它或更改为另一个值没有什么不同。
  • 嗯,也许设置cell.height

标签: ios swift swift3 uiimageview eureka-forms


【解决方案1】:

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

【讨论】:

  • 谢谢。试过了,不行。调试器显示“[LayoutConstraints] 无法同时满足约束。”试图潜入 Eureka 的源代码。是否有任何指向“自动布局”或我应该注意的关键字链接?
猜你喜欢
  • 2023-03-12
  • 2014-08-24
  • 1970-01-01
  • 2014-07-20
  • 1970-01-01
  • 2010-11-02
  • 1970-01-01
  • 1970-01-01
  • 2018-07-26
相关资源
最近更新 更多